From c411324d8a15527d95cd6175920faf60dd0fffbc Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Mon, 14 Oct 2019 16:43:28 +0200 Subject: [PATCH] Added some updates --- modules/core/main_window.ts | 4 +++ .../renderer/connection/VoiceConnection.ts | 20 +++++++++++--- native/serverconnection/exports/exports.d.ts | 3 +++ .../src/connection/audio/AudioSender.cpp | 8 ++++++ .../src/connection/audio/AudioSender.h | 4 +++ .../src/connection/audio/VoiceConnection.cpp | 26 ++++++++++++++++++- .../src/connection/audio/VoiceConnection.h | 1 + package.json | 2 +- 8 files changed, 62 insertions(+), 6 deletions(-) diff --git a/modules/core/main_window.ts b/modules/core/main_window.ts index e08af47..f102877 100644 --- a/modules/core/main_window.ts +++ b/modules/core/main_window.ts @@ -26,6 +26,10 @@ function spawn_main_window(entry_point: string) { main_window = new BrowserWindow({ width: 800, height: 600, + + minHeight: 600, + minWidth: 600, + show: false, webPreferences: { webSecurity: false, diff --git a/modules/renderer/connection/VoiceConnection.ts b/modules/renderer/connection/VoiceConnection.ts index eb4e7a0..598be06 100644 --- a/modules/renderer/connection/VoiceConnection.ts +++ b/modules/renderer/connection/VoiceConnection.ts @@ -49,7 +49,7 @@ export namespace _audio { this.connection.client.update_voice_status(undefined); }; - recorder.callback_start = this.handleVoiceStarted.bind(this); + recorder.callback_start = this.on_voice_started.bind(this); recorder.callback_stop = this.handleVoiceEnded.bind(this); recorder.callback_support_change = () => { @@ -88,10 +88,22 @@ export namespace _audio { //TODO } - private handleVoiceStarted() { + private on_voice_started() { const chandler = this.connection.client; - console.log(tr("Local voice started")); - chandler.getClient().speaking = true; + if(chandler.client_status.input_muted) { + /* evil hack due to the settings :D */ + log.warn(LogCategory.VOICE, tr("Received local voice started event, even thou we're muted! Do not send any voice.")); + if(this.handle) { + this.handle.enable_voice_send(false); + } + return; + } + + log.info(LogCategory.VOICE, tr("Local voice started")); + this.handle.enable_voice_send(true); + + const ch = chandler.getClient(); + if(ch) ch.speaking = true; } connected(): boolean { diff --git a/native/serverconnection/exports/exports.d.ts b/native/serverconnection/exports/exports.d.ts index 8bef782..120fa78 100644 --- a/native/serverconnection/exports/exports.d.ts +++ b/native/serverconnection/exports/exports.d.ts @@ -42,6 +42,9 @@ declare module "teaclient_connection" { get_encoder_codec() : number; set_encoder_codec(codec: number); + + /* could may throw an exception when the underlying voice sender has been deallocated */ + enable_voice_send(flag: boolean); } export interface NativeServerConnection { diff --git a/native/serverconnection/src/connection/audio/AudioSender.cpp b/native/serverconnection/src/connection/audio/AudioSender.cpp index 161da1c..1ba2230 100644 --- a/native/serverconnection/src/connection/audio/AudioSender.cpp +++ b/native/serverconnection/src/connection/audio/AudioSender.cpp @@ -53,6 +53,10 @@ bool VoiceSender::initialize_codec(std::string& error, connection::codec::value return true; } +void VoiceSender::set_voice_send_enabled(bool flag) { + this->voice_send_enabled = flag; +} + void VoiceSender::send_data(const void *data, size_t samples, size_t rate, size_t channels) { unique_lock lock(this->_execute_lock); if(!this->handle) { @@ -61,6 +65,10 @@ void VoiceSender::send_data(const void *data, size_t samples, size_t rate, size_ } lock.unlock(); + if(!this->voice_send_enabled) { + log_warn(category::voice_connection, tr("Dropping raw audio frame because voice sending has been disabled!")); + return; + } auto frame = make_unique(); frame->sample_rate = rate; diff --git a/native/serverconnection/src/connection/audio/AudioSender.h b/native/serverconnection/src/connection/audio/AudioSender.h index abfc471..eddf538 100644 --- a/native/serverconnection/src/connection/audio/AudioSender.h +++ b/native/serverconnection/src/connection/audio/AudioSender.h @@ -31,6 +31,8 @@ namespace tc { void finalize(); void send_data(const void* /* buffer */, size_t /* samples */, size_t /* sample rate */, size_t /* channels */); void send_stop(); + + void set_voice_send_enabled(bool /* flag */); private: std::weak_ptr _ref; VoiceConnection* handle; @@ -79,6 +81,8 @@ namespace tc { std::mutex raw_audio_buffer_lock; std::deque> raw_audio_buffers; + bool voice_send_enabled = false; + void encode_raw_frame(const std::unique_ptr&); void event_execute(const std::chrono::system_clock::time_point &point) override; }; diff --git a/native/serverconnection/src/connection/audio/VoiceConnection.cpp b/native/serverconnection/src/connection/audio/VoiceConnection.cpp index 2d4916d..e01b1c9 100644 --- a/native/serverconnection/src/connection/audio/VoiceConnection.cpp +++ b/native/serverconnection/src/connection/audio/VoiceConnection.cpp @@ -47,6 +47,8 @@ NAN_MODULE_INIT(VoiceConnectionWrap::Init) { Nan::SetPrototypeMethod(klass, "get_encoder_codec", VoiceConnectionWrap::_get_encoder_codec); Nan::SetPrototypeMethod(klass, "set_encoder_codec", VoiceConnectionWrap::_set_encoder_codec); + Nan::SetPrototypeMethod(klass, "enable_voice_send", VoiceConnectionWrap::_enable_voice_send); + constructor().Reset(Nan::GetFunction(klass).ToLocalChecked()); } @@ -234,7 +236,29 @@ NAN_METHOD(VoiceConnectionWrap::_set_encoder_codec) { return; } - handle->set_encoder_codec(info[0]->NumberValue(Nan::GetCurrentContext()).FromMaybe(0)); + handle->set_encoder_codec((uint8_t) info[0]->NumberValue(Nan::GetCurrentContext()).FromMaybe(0)); +} + +NAN_METHOD(VoiceConnectionWrap::_enable_voice_send) { + auto _this = ObjectWrap::Unwrap(info.Holder()); + auto handle = _this->handle.lock(); + if(!handle) { + Nan::ThrowError("handle has been deallocated"); + return; + } + + if(info.Length() != 1 || !info[0]->IsBoolean()) { + Nan::ThrowError("Invalid arguments"); + return; + } + + auto sender = handle->voice_sender(); + if(!sender) { + Nan::ThrowError("Voice sender has been deallocated"); + return; + } + + sender->set_voice_send_enabled(info[0]->BooleanValue(info.GetIsolate())); } diff --git a/native/serverconnection/src/connection/audio/VoiceConnection.h b/native/serverconnection/src/connection/audio/VoiceConnection.h index 9f0054e..9347dee 100644 --- a/native/serverconnection/src/connection/audio/VoiceConnection.h +++ b/native/serverconnection/src/connection/audio/VoiceConnection.h @@ -50,6 +50,7 @@ namespace tc { static NAN_METHOD(_get_encoder_codec); static NAN_METHOD(_set_encoder_codec); + static NAN_METHOD(_enable_voice_send); void release_recorder(); diff --git a/package.json b/package.json index e60c21a..e26c5e8 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "start": "electron --js-flags='--expose-gc' --debug --dev-tools --disable-hardware-acceleration .", "start-d": "electron . --disable-hardware-acceleration --debug -t -u http://clientapi.teaspeak.dev/", "start-wd": "electron . --disable-hardware-acceleration --debug -t -su http://localhost/TeaWeb/client-api/environment/", - "start-d1": "electron . --disable-hardware-acceleration --debug -t --gdb -su http://clientapi.teaspeak.de/ --updater-ui-loader_type=0", + "start-d1": "electron . --disable-hardware-acceleration --debug -t --gdb -su http://clientapi.teaspeak.dev/ --updater-ui-loader_type=0", "start-n": "electron . -t --disable-hardware-acceleration --no-single-instance -u=https://clientapi.teaspeak.de/ -d --updater-ui-loader_type=0", "start-01": "electron . --updater-channel=test -u=http://dev.clientapi.teaspeak.de/ -d --updater-ui-loader_type=0 --updater-local-version=1.0.1", "compile-sass": "sass --update .:.",