From 26007a51c4654c240e73e86973b78ff7739be13a Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Fri, 19 Jul 2019 22:16:27 +0200 Subject: [PATCH] Fixed some stuff --- .../src/connection/ServerConnection.cpp | 11 +++++++---- native/serverconnection/test/js/main.ts | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/native/serverconnection/src/connection/ServerConnection.cpp b/native/serverconnection/src/connection/ServerConnection.cpp index 86dc0a2..eecf4ed 100644 --- a/native/serverconnection/src/connection/ServerConnection.cpp +++ b/native/serverconnection/src/connection/ServerConnection.cpp @@ -487,13 +487,17 @@ void ServerConnection::send_voice_data(const void *buffer, size_t buffer_length, if(head) /* head packet */ packet->enable_flag(ts::protocol::PacketFlag::Compressed); - this->protocol_handler->send_packet(packet); + if((rand() % 10) < 2) { + log_info(category::connection, tr("Dropping voice packet")); + } else { + this->protocol_handler->send_packet(packet); + } } void ServerConnection::close_connection() { - if(this_thread::get_id() == this->socket->io_thread().get_id()) { + lock_guard lock(this->disconnect_lock); + if(this->socket && this_thread::get_id() == this->socket->io_thread().get_id()) { logger::debug(category::connection, tr("close_connection() called in IO thread. Closing connection within event loop!")); - lock_guard lock(this->disconnect_lock); if(!this->event_loop_execute_connection_close) { this->event_loop_execute_connection_close = true; this->event_condition.notify_one(); @@ -501,7 +505,6 @@ void ServerConnection::close_connection() { return; } - lock_guard lock(this->disconnect_lock); this->event_loop_execute_connection_close = false; if(this->socket) { this->socket->finalize(); diff --git a/native/serverconnection/test/js/main.ts b/native/serverconnection/test/js/main.ts index 0445eff..136728e 100644 --- a/native/serverconnection/test/js/main.ts +++ b/native/serverconnection/test/js/main.ts @@ -147,6 +147,7 @@ const do_connect = () => { }; consumer.callback_data = buffer => { + console.log("Sending voice data"); connection.send_voice_data_raw(buffer, consumer.channels, consumer.sample_rate, true); //stream.write_data_rated(buffer.buffer, true, consumer.sample_rate); }; @@ -177,9 +178,11 @@ setInterval(() => { global.gc(); }, 1000); +let a_map = [consumer, recorder]; /* keep the object alive */ setTimeout(() => { connection.connected(); + a_map = a_map.filter(e => true); }, 1000); connection_list.push(connection); \ No newline at end of file