Allowing the webclient to whisper
This commit is contained in:
parent
5ed16d3756
commit
5cf3b0b75c
2
rtclib
2
rtclib
@ -1 +1 @@
|
|||||||
Subproject commit cbebf66d3eba2e16e4b7b01161129031ced358f5
|
Subproject commit d4771462dbe5fe11fe53a19eb43f8cfeb7bd110c
|
@ -153,6 +153,15 @@ bool WhisperHandler::process_packet(const protocol::ClientPacketParser &packet,
|
|||||||
return this->session_state == SessionState::Initialized;
|
return this->session_state == SessionState::Initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WhisperHandler::signal_session_reset() {
|
||||||
|
auto server = this->handle->getServer();
|
||||||
|
if(!server) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
server->rtc_server().reset_whisper_session(this->handle->rtc_client_id);
|
||||||
|
}
|
||||||
|
|
||||||
void WhisperHandler::handle_session_reset() {
|
void WhisperHandler::handle_session_reset() {
|
||||||
this->session_state = SessionState::Uninitialized;
|
this->session_state = SessionState::Uninitialized;
|
||||||
if(this->whisper_head_ptr) {
|
if(this->whisper_head_ptr) {
|
||||||
|
@ -47,6 +47,7 @@ namespace ts::server::whisper {
|
|||||||
ts::command_result initialize_session_new(uint32_t /* stream id */, uint8_t /* type */, uint8_t /* target */, uint64_t /* type id */);
|
ts::command_result initialize_session_new(uint32_t /* stream id */, uint8_t /* type */, uint8_t /* target */, uint64_t /* type id */);
|
||||||
ts::command_result initialize_session_old(uint32_t /* stream id */, const uint16_t* /* client ids */, size_t /* client count */, const uint64_t* /* channel ids */, size_t /* channel count */);
|
ts::command_result initialize_session_old(uint32_t /* stream id */, const uint16_t* /* client ids */, size_t /* client count */, const uint64_t* /* channel ids */, size_t /* channel count */);
|
||||||
|
|
||||||
|
void signal_session_reset();
|
||||||
void handle_session_reset();
|
void handle_session_reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -23,7 +23,7 @@ using namespace ts;
|
|||||||
using namespace ts::server;
|
using namespace ts::server;
|
||||||
using namespace ts::protocol;
|
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);
|
memtrack::allocated<WebClient>(this);
|
||||||
|
|
||||||
assert(server->getTS());
|
assert(server->getTS());
|
||||||
@ -535,21 +535,13 @@ command_result WebClient::handleCommandWhisperSessionInitialize(Command &command
|
|||||||
return command_result{error::server_unbound};
|
return command_result{error::server_unbound};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto stream_id = command["stream_id"].as<uint32_t>();
|
||||||
if(command.hasParm("new")) {
|
if(command.hasParm("new")) {
|
||||||
auto type = command["type"].as<uint8_t>();
|
auto type = command["type"].as<uint8_t>();
|
||||||
auto target = command["target"].as<uint8_t>();
|
auto target = command["target"].as<uint8_t>();
|
||||||
auto target_id = command["id"].as<uint64_t>();
|
auto target_id = command["id"].as<uint64_t>();
|
||||||
|
|
||||||
std::lock_guard whisper_buffer_lock{this->whisper.mutex};
|
return this->whisper_handler_.initialize_session_new(stream_id, type, target, target_id);
|
||||||
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};
|
|
||||||
} else {
|
} else {
|
||||||
if(command.bulkCount() > 255) {
|
if(command.bulkCount() > 255) {
|
||||||
return command_result{error::parameter_invalid_count};
|
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 */
|
return this->whisper_handler_.initialize_session_old(stream_id, &client_ids[0], client_ids.size(), &channel_ids[0], channel_ids.size());
|
||||||
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 command_result{error::ok};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
command_result WebClient::handleCommandWhisperSessionReset(Command &command) {
|
command_result WebClient::handleCommandWhisperSessionReset(Command &command) {
|
||||||
std::lock_guard whisper_buffer_lock{this->whisper.mutex};
|
this->whisper_handler_.signal_session_reset();
|
||||||
this->whisper.is_set = false;
|
|
||||||
return command_result{error::ok};
|
return command_result{error::ok};
|
||||||
}
|
}
|
@ -10,6 +10,7 @@
|
|||||||
#include <opus/opus.h>
|
#include <opus/opus.h>
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#include <EventLoop.h>
|
#include <EventLoop.h>
|
||||||
|
#include "../shared/WhisperHandler.h"
|
||||||
|
|
||||||
namespace ts::server {
|
namespace ts::server {
|
||||||
class WebControlServer;
|
class WebControlServer;
|
||||||
@ -51,6 +52,8 @@ namespace ts::server {
|
|||||||
::event* readEvent;
|
::event* readEvent;
|
||||||
::event* writeEvent;
|
::event* writeEvent;
|
||||||
|
|
||||||
|
std::shared_ptr<event::ProxiedEventEntry<WebClient>> event_handle_packet;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint8_t current_id{0};
|
uint8_t current_id{0};
|
||||||
std::chrono::system_clock::time_point last_request;
|
std::chrono::system_clock::time_point last_request;
|
||||||
@ -77,12 +80,7 @@ namespace ts::server {
|
|||||||
std::thread flush_thread;
|
std::thread flush_thread;
|
||||||
std::recursive_mutex close_lock;
|
std::recursive_mutex close_lock;
|
||||||
|
|
||||||
struct {
|
whisper::WhisperHandler whisper_handler_;
|
||||||
std::mutex mutex{};
|
|
||||||
pipes::buffer target_header{};
|
|
||||||
bool is_new_header{false};
|
|
||||||
bool is_set{false};
|
|
||||||
} whisper;
|
|
||||||
private:
|
private:
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
@ -93,8 +91,6 @@ namespace ts::server {
|
|||||||
void processNextMessage(const std::chrono::system_clock::time_point& /* scheduled */);
|
void processNextMessage(const std::chrono::system_clock::time_point& /* scheduled */);
|
||||||
void registerMessageProcess();
|
void registerMessageProcess();
|
||||||
|
|
||||||
std::shared_ptr<event::ProxiedEventEntry<WebClient>> event_handle_packet;
|
|
||||||
|
|
||||||
//WS events
|
//WS events
|
||||||
void onWSConnected();
|
void onWSConnected();
|
||||||
void onWSDisconnected(const std::string& reason);
|
void onWSDisconnected(const std::string& reason);
|
||||||
|
@ -73,6 +73,7 @@ extern uint32_t librtc_client_broadcast(void* /* server */, uint32_t /* client i
|
|||||||
extern void librtc_destroy_channel(void* /* server */, uint32_t /* channel */);
|
extern void librtc_destroy_channel(void* /* server */, uint32_t /* channel */);
|
||||||
|
|
||||||
extern const char* librtc_whisper_configure(void* /* server */, uint32_t /* client id */, uint32_t /* source stream id */, uint32_t* /* client ids */, uint32_t /* client id count */);
|
extern const char* librtc_whisper_configure(void* /* server */, uint32_t /* client id */, uint32_t /* source stream id */, uint32_t* /* client ids */, uint32_t /* client id count */);
|
||||||
|
extern void librtc_whisper_reset(void* /* server */, uint32_t /* client id */);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
};
|
};
|
||||||
|
@ -367,6 +367,10 @@ bool Server::configure_whisper_session(std::string &error, RTCClientId client_id
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::reset_whisper_session(RTCClientId client_id) {
|
||||||
|
librtc_whisper_reset(this->server_ptr, client_id);
|
||||||
|
}
|
||||||
|
|
||||||
NativeAudioSourceSupplier::NativeAudioSourceSupplier(void *ptr) : sender_ptr{ptr} {}
|
NativeAudioSourceSupplier::NativeAudioSourceSupplier(void *ptr) : sender_ptr{ptr} {}
|
||||||
NativeAudioSourceSupplier::NativeAudioSourceSupplier(NativeAudioSourceSupplier &&other) noexcept : sender_ptr{other.sender_ptr} {
|
NativeAudioSourceSupplier::NativeAudioSourceSupplier(NativeAudioSourceSupplier &&other) noexcept : sender_ptr{other.sender_ptr} {
|
||||||
other.sender_ptr = nullptr;
|
other.sender_ptr = nullptr;
|
||||||
|
@ -61,6 +61,7 @@ namespace ts::rtc {
|
|||||||
|
|
||||||
/* whisper actions */
|
/* whisper actions */
|
||||||
bool configure_whisper_session(std::string& /* error */, RTCClientId /* client id */, uint32_t /* source stream id */, RTCClientId* /* session members */, size_t /* session member count */);
|
bool configure_whisper_session(std::string& /* error */, RTCClientId /* client id */, uint32_t /* source stream id */, RTCClientId* /* session members */, size_t /* session member count */);
|
||||||
|
void reset_whisper_session(RTCClientId /* client id */);
|
||||||
private:
|
private:
|
||||||
void* server_ptr{nullptr};
|
void* server_ptr{nullptr};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user