Allowing the webclient to whisper
This commit is contained in:
@@ -23,7 +23,7 @@ using namespace ts;
|
||||
using namespace ts::server;
|
||||
using namespace ts::protocol;
|
||||
|
||||
WebClient::WebClient(WebControlServer* server, int fd) : SpeakingClient(server->getTS()->getSql(), server->getTS()), handle(server) {
|
||||
WebClient::WebClient(WebControlServer* server, int fd) : SpeakingClient(server->getTS()->getSql(), server->getTS()), handle(server), whisper_handler_{this} {
|
||||
memtrack::allocated<WebClient>(this);
|
||||
|
||||
assert(server->getTS());
|
||||
@@ -535,21 +535,13 @@ command_result WebClient::handleCommandWhisperSessionInitialize(Command &command
|
||||
return command_result{error::server_unbound};
|
||||
}
|
||||
|
||||
auto stream_id = command["stream_id"].as<uint32_t>();
|
||||
if(command.hasParm("new")) {
|
||||
auto type = command["type"].as<uint8_t>();
|
||||
auto target = command["target"].as<uint8_t>();
|
||||
auto target_id = command["id"].as<uint64_t>();
|
||||
|
||||
std::lock_guard whisper_buffer_lock{this->whisper.mutex};
|
||||
this->whisper.is_set = true;
|
||||
this->whisper.is_new_header = true;
|
||||
this->whisper.target_header.resize(10);
|
||||
|
||||
this->whisper.target_header[0] = type;
|
||||
this->whisper.target_header[1] = target;
|
||||
le2be64(target_id, &this->whisper.target_header[2]);
|
||||
|
||||
return command_result{error::ok};
|
||||
return this->whisper_handler_.initialize_session_new(stream_id, type, target, target_id);
|
||||
} else {
|
||||
if(command.bulkCount() > 255) {
|
||||
return command_result{error::parameter_invalid_count};
|
||||
@@ -586,39 +578,11 @@ command_result WebClient::handleCommandWhisperSessionInitialize(Command &command
|
||||
}
|
||||
}
|
||||
|
||||
/* check if we're exceeding the protocol limit */
|
||||
if(client_ids.size() > 255) {
|
||||
return command_result{error::whisper_too_many_targets};
|
||||
}
|
||||
if(channel_ids.size() > 255) {
|
||||
return command_result{error::whisper_too_many_targets};
|
||||
}
|
||||
|
||||
/* generate the whisper target header */
|
||||
std::lock_guard whisper_buffer_lock{this->whisper.mutex};
|
||||
this->whisper.is_set = true;
|
||||
this->whisper.is_new_header = false;
|
||||
this->whisper.target_header.resize(client_ids.size() * 2 + channel_ids.size() * 8 + 2);
|
||||
static_assert(sizeof(ChannelId) == 8);
|
||||
static_assert(sizeof(ClientId) == 2);
|
||||
|
||||
size_t offset{0};
|
||||
|
||||
this->whisper.target_header[0] = channel_ids.size();
|
||||
this->whisper.target_header[1] = client_ids.size();
|
||||
offset += 2;
|
||||
|
||||
memcpy(this->whisper.target_header.data_ptr<char>() + offset, channel_ids.data(), channel_ids.size() * 8);
|
||||
offset += channel_ids.size() * 8;
|
||||
|
||||
memcpy(this->whisper.target_header.data_ptr<char>() + offset, client_ids.data(), client_ids.size() * 2);
|
||||
//offset += channel_ids.size() * 2;
|
||||
return this->whisper_handler_.initialize_session_old(stream_id, &client_ids[0], client_ids.size(), &channel_ids[0], channel_ids.size());
|
||||
}
|
||||
return command_result{error::ok};
|
||||
}
|
||||
|
||||
command_result WebClient::handleCommandWhisperSessionReset(Command &command) {
|
||||
std::lock_guard whisper_buffer_lock{this->whisper.mutex};
|
||||
this->whisper.is_set = false;
|
||||
this->whisper_handler_.signal_session_reset();
|
||||
return command_result{error::ok};
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <opus/opus.h>
|
||||
#include <json/json.h>
|
||||
#include <EventLoop.h>
|
||||
#include "../shared/WhisperHandler.h"
|
||||
|
||||
namespace ts::server {
|
||||
class WebControlServer;
|
||||
@@ -51,6 +52,8 @@ namespace ts::server {
|
||||
::event* readEvent;
|
||||
::event* writeEvent;
|
||||
|
||||
std::shared_ptr<event::ProxiedEventEntry<WebClient>> event_handle_packet;
|
||||
|
||||
struct {
|
||||
uint8_t current_id{0};
|
||||
std::chrono::system_clock::time_point last_request;
|
||||
@@ -77,12 +80,7 @@ namespace ts::server {
|
||||
std::thread flush_thread;
|
||||
std::recursive_mutex close_lock;
|
||||
|
||||
struct {
|
||||
std::mutex mutex{};
|
||||
pipes::buffer target_header{};
|
||||
bool is_new_header{false};
|
||||
bool is_set{false};
|
||||
} whisper;
|
||||
whisper::WhisperHandler whisper_handler_;
|
||||
private:
|
||||
void initialize();
|
||||
|
||||
@@ -93,8 +91,6 @@ namespace ts::server {
|
||||
void processNextMessage(const std::chrono::system_clock::time_point& /* scheduled */);
|
||||
void registerMessageProcess();
|
||||
|
||||
std::shared_ptr<event::ProxiedEventEntry<WebClient>> event_handle_packet;
|
||||
|
||||
//WS events
|
||||
void onWSConnected();
|
||||
void onWSDisconnected(const std::string& reason);
|
||||
|
||||
Reference in New Issue
Block a user