2020-11-08 16:08:24 +01:00
|
|
|
/* conference_commands.c
|
2014-11-15 04:15:59 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Toxic All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Toxic.
|
|
|
|
*
|
|
|
|
* Toxic is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Toxic is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
#include <stdlib.h>
|
2020-04-18 02:00:00 +02:00
|
|
|
#include <string.h>
|
2014-11-15 04:15:59 +01:00
|
|
|
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "conference.h"
|
2014-11-15 04:15:59 +01:00
|
|
|
#include "line_info.h"
|
|
|
|
#include "log.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "misc_tools.h"
|
|
|
|
#include "toxic.h"
|
|
|
|
#include "windows.h"
|
2014-11-15 04:15:59 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
static void print_err(ToxWindow *self, const char *error_str)
|
|
|
|
{
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s", error_str);
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
void cmd_conference_set_title(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2014-11-15 04:15:59 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Conference_Title err;
|
2020-11-17 22:05:20 +01:00
|
|
|
char title[CONFERENCE_MAX_TITLE_LENGTH + 1];
|
2014-11-15 04:15:59 +01:00
|
|
|
|
|
|
|
if (argc < 1) {
|
2016-12-18 06:01:51 +01:00
|
|
|
size_t tlen = tox_conference_get_title_size(m, self->num, &err);
|
2014-11-15 21:55:45 +01:00
|
|
|
|
2019-06-30 20:51:13 +02:00
|
|
|
if (err != TOX_ERR_CONFERENCE_TITLE_OK || tlen >= sizeof(title)) {
|
2020-05-07 02:00:00 +02:00
|
|
|
print_err(self, "Title is not set");
|
2016-12-18 06:01:51 +01:00
|
|
|
return;
|
2014-11-15 21:55:45 +01:00
|
|
|
}
|
|
|
|
|
2016-12-18 06:01:51 +01:00
|
|
|
if (!tox_conference_get_title(m, self->num, (uint8_t *) title, &err)) {
|
2020-05-07 02:00:00 +02:00
|
|
|
print_err(self, "Title is not set");
|
2016-12-18 06:01:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
title[tlen] = '\0';
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Title is set to: %s", title);
|
2016-12-18 06:01:51 +01:00
|
|
|
|
2014-11-15 04:15:59 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
size_t len = strlen(argv[1]);
|
|
|
|
|
|
|
|
if (len >= sizeof(title)) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to set title: max length exceeded.");
|
2020-11-17 22:05:20 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-07 23:30:43 +02:00
|
|
|
snprintf(title, sizeof(title), "%s", argv[1]);
|
2014-11-15 04:15:59 +01:00
|
|
|
|
2016-12-18 06:01:51 +01:00
|
|
|
if (!tox_conference_set_title(m, self->num, (uint8_t *) title, len, &err)) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to set title (error %d)", err);
|
2014-11-15 04:15:59 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-17 22:05:20 +01:00
|
|
|
conference_rename_log_path(m, self->num, title); // must be called first
|
|
|
|
|
|
|
|
conference_set_title(self, self->num, title, len);
|
2014-11-15 04:15:59 +01:00
|
|
|
|
|
|
|
char selfnick[TOX_MAX_NAME_LENGTH];
|
2015-03-26 03:56:45 +01:00
|
|
|
tox_self_get_name(m, (uint8_t *) selfnick);
|
2020-11-30 23:55:57 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
size_t sn_len = tox_self_get_name_size(m);
|
2014-11-15 04:15:59 +01:00
|
|
|
selfnick[sn_len] = '\0';
|
|
|
|
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, true, selfnick, NULL, NAME_CHANGE, 0, 0, " set the conference title to: %s", title);
|
2014-11-15 04:15:59 +01:00
|
|
|
|
2020-10-24 20:44:41 +02:00
|
|
|
char tmp_event[MAX_STR_SIZE + 20];
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(tmp_event, sizeof(tmp_event), "set title to %s", title);
|
2014-11-15 04:15:59 +01:00
|
|
|
write_to_log(tmp_event, selfnick, self->chatwin->log, true);
|
|
|
|
}
|
2020-05-07 02:00:00 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
#ifdef AUDIO
|
2020-05-07 02:00:00 +02:00
|
|
|
void cmd_enable_audio(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
|
|
|
bool enable;
|
|
|
|
|
|
|
|
if (argc == 1 && !strcasecmp(argv[1], "on")) {
|
|
|
|
enable = true;
|
|
|
|
} else if (argc == 1 && !strcasecmp(argv[1], "off")) {
|
|
|
|
enable = false;
|
|
|
|
} else {
|
2020-05-07 02:00:00 +02:00
|
|
|
print_err(self, "Please specify: on | off");
|
2020-05-07 02:00:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-20 16:16:47 +01:00
|
|
|
if (enable ? enable_conference_audio(self, m, self->num) : disable_conference_audio(self, m, self->num)) {
|
2020-11-18 22:57:26 +01:00
|
|
|
print_err(self, enable ? "Enabled conference audio. Use the '/ptt' command to toggle Push-To-Talk."
|
|
|
|
: "Disabled conference audio");
|
2020-05-07 02:00:00 +02:00
|
|
|
} else {
|
2020-05-07 02:00:00 +02:00
|
|
|
print_err(self, enable ? "Failed to enable audio" : "Failed to disable audio");
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_conference_mute(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
|
|
|
UNUSED_VAR(window);
|
|
|
|
|
|
|
|
if (argc < 1) {
|
|
|
|
if (conference_mute_self(self->num)) {
|
2020-05-07 02:00:00 +02:00
|
|
|
print_err(self, "Toggled self audio mute status");
|
2020-05-07 02:00:00 +02:00
|
|
|
} else {
|
2020-05-07 02:00:00 +02:00
|
|
|
print_err(self, "No audio input to mute");
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NameListEntry *entries[16];
|
|
|
|
uint32_t n = get_name_list_entries_by_prefix(self->num, argv[1], entries, 16);
|
|
|
|
|
|
|
|
if (n == 0) {
|
2020-05-07 02:00:00 +02:00
|
|
|
print_err(self, "No such peer");
|
2020-05-07 02:00:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n > 1) {
|
2020-05-07 02:00:00 +02:00
|
|
|
print_err(self, "Multiple matching peers (use /mute [public key] to disambiguate):");
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < n; ++i) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s: %s", entries[i]->pubkey_str, entries[i]->name);
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conference_mute_peer(m, self->num, entries[0]->peernum)) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Toggled audio mute status of %s", entries[0]->name);
|
2020-05-07 02:00:00 +02:00
|
|
|
} else {
|
2020-11-18 22:57:26 +01:00
|
|
|
print_err(self, "Peer is not on the call");
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_conference_sense(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
|
|
|
if (argc == 0) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Current VAD threshold: %.1f",
|
2020-05-07 02:00:00 +02:00
|
|
|
(double) conference_get_VAD_threshold(self->num));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
print_err(self, "Only one argument allowed.");
|
|
|
|
return;
|
|
|
|
}
|
2020-05-07 02:00:00 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
char *end;
|
|
|
|
float value = strtof(argv[1], &end);
|
|
|
|
|
|
|
|
if (*end) {
|
|
|
|
print_err(self, "Invalid input");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conference_set_VAD_threshold(self->num, value)) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Set VAD threshold to %.1f", (double) value);
|
2020-05-07 02:00:00 +02:00
|
|
|
} else {
|
|
|
|
print_err(self, "Failed to set conference audio input sensitivity.");
|
|
|
|
}
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
2020-11-18 22:57:26 +01:00
|
|
|
|
|
|
|
void cmd_conference_push_to_talk(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
|
|
|
bool enable;
|
|
|
|
|
|
|
|
if (argc == 1 && !strcasecmp(argv[1], "on")) {
|
|
|
|
enable = true;
|
|
|
|
} else if (argc == 1 && !strcasecmp(argv[1], "off")) {
|
|
|
|
enable = false;
|
|
|
|
} else {
|
|
|
|
print_err(self, "Please specify: on | off");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!toggle_conference_push_to_talk(self->num, enable)) {
|
|
|
|
print_err(self, "Failed to toggle push to talk.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_err(self, enable ? "Push-To-Talk is enabled. Push F2 to activate" : "Push-To-Talk is disabled");
|
|
|
|
}
|
2020-05-07 02:00:00 +02:00
|
|
|
#endif /* AUDIO */
|