Added possibilities to configure the ICE agent
This commit is contained in:
parent
83fa79a51d
commit
225c006140
@ -714,7 +714,14 @@ void SpeakingClient::processJoin() {
|
||||
/* TODO: Will be a RTP client later on, just without audio */
|
||||
this->rtc_client_id = this->server->rtc_server().create_native_client(dynamic_pointer_cast<SpeakingClient>(this->ref()));
|
||||
} else if(this->getType() == ClientType::CLIENT_WEB) {
|
||||
this->rtc_client_id = this->server->rtc_server().create_rtp_client(dynamic_pointer_cast<SpeakingClient>(this->ref()));
|
||||
std::string error;
|
||||
auto result = this->server->rtc_server().create_rtp_client(dynamic_pointer_cast<SpeakingClient>(this->ref()), error);
|
||||
if(result > 0) {
|
||||
this->rtc_client_id = result;
|
||||
} else {
|
||||
this->rtc_client_id = 0;
|
||||
logCritical(this->getServerId(), "{} Failed to configure RTC session: {}", CLIENT_STR_LOG_PREFIX, error);
|
||||
}
|
||||
}
|
||||
this->rtc_session_pending_describe = true;
|
||||
|
||||
|
@ -12,6 +12,8 @@ struct NativeCallbacks {
|
||||
void(*log)(uint8_t /* level */, const void* /* callback data */, const char* /* message */, uint32_t /* length */);
|
||||
void(*free_client_data)(const void*);
|
||||
|
||||
uint32_t(*rtc_configure)(const void* /* callback data */, void* /* configure callback data */);
|
||||
|
||||
void(*client_stream_assignment)(const void* /* callback data */, uint32_t /* stream id */, const void* /* source callback data */);
|
||||
void(*client_offer_generated)(const void* /* callback data */, const char* /* offer */, size_t /* offer length */);
|
||||
|
||||
@ -21,6 +23,18 @@ struct NativeCallbacks {
|
||||
void(*client_audio_sender_data)(const void* /* callback data */, const void* /* source callback data */, uint8_t /* mode */, uint16_t /* seq. no. */, uint8_t /* codec */, const void* /* data */, uint32_t /* length */);
|
||||
};
|
||||
|
||||
struct RtpClientConfigureOptions {
|
||||
uint16_t min_port;
|
||||
uint16_t max_port;
|
||||
|
||||
bool ice_tcp;
|
||||
bool ice_udp;
|
||||
bool ice_upnp;
|
||||
|
||||
const char* stun_host;
|
||||
uint16_t stun_port;
|
||||
};
|
||||
|
||||
extern const char* librtc_version();
|
||||
extern void librtc_free_str(const char* /* ptr */);
|
||||
|
||||
@ -29,10 +43,12 @@ extern const char* librtc_init(const NativeCallbacks* /* */, size_t /* size of t
|
||||
extern void* librtc_create_server();
|
||||
extern void librtc_destroy_server(void* /* server */);
|
||||
|
||||
extern uint32_t librtc_create_rtp_client(void* /* server */, void* /* callback data */);
|
||||
extern uint32_t librtc_create_rtp_client(void* /* server */, void* /* callback data */, const char** /* error ptr */);
|
||||
extern uint32_t librtc_create_native_client(void* /* server */, void* /* callback data */);
|
||||
extern void librtc_destroy_client(void* /* server */, uint32_t /* client id */);
|
||||
|
||||
extern const char* librtc_rtc_configure(void* /* callback data */, const RtpClientConfigureOptions* /* config */, size_t /* config size */);
|
||||
|
||||
extern const char* librtc_reset_rtp_session(void* /* server */, uint32_t /* client id */);
|
||||
extern const char* librtc_apply_remote_description(void* /* server */, uint32_t /* client id */, uint32_t /* mode */, const char* /* description */);
|
||||
extern const char* librtc_generate_local_description(void* /* server */, uint32_t /* client id */, char** /* description */);
|
||||
|
@ -62,6 +62,38 @@ void librtc_callback_free_client_data(const void* data) {
|
||||
delete (LibCallbackData*) data;
|
||||
}
|
||||
|
||||
uint32_t librtc_callback_rtc_configure(const void* callback_data_ptr, void* configure_ptr) {
|
||||
auto callback_data = (LibCallbackData*) callback_data_ptr;
|
||||
|
||||
auto target_client = callback_data->weak_ref.lock();
|
||||
if(!target_client) { return 2; }
|
||||
|
||||
RtpClientConfigureOptions options{};
|
||||
memset(&options, 0, sizeof(options));
|
||||
|
||||
options.ice_tcp = config::web::tcp_enabled;
|
||||
options.ice_udp = config::web::udp_enabled;
|
||||
options.ice_upnp = config::web::enable_upnp;
|
||||
options.max_port = config::web::webrtc_port_min;
|
||||
options.max_port = config::web::webrtc_port_max;
|
||||
|
||||
std::string stun_host{config::web::stun_host};
|
||||
options.stun_host = stun_host.c_str();
|
||||
options.stun_port = config::web::stun_port;
|
||||
if(!config::web::stun_enabled) {
|
||||
options.stun_port = 0;
|
||||
options.stun_host = nullptr;
|
||||
}
|
||||
|
||||
auto result = librtc_rtc_configure(configure_ptr, &options, sizeof(options));
|
||||
if(result) {
|
||||
logError(target_client->getServerId(), "{} Failed to configure RTC connection: {}", CLIENT_STR_LOG_PREFIX_(target_client), result);
|
||||
librtc_free_str(result);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void librtc_callback_client_stream_assignment(const void* callback_data_ptr, uint32_t stream_id, const void* source_data_ptr) {
|
||||
auto callback_data = (LibCallbackData*) callback_data_ptr;
|
||||
auto source_data = (LibCallbackData*) source_data_ptr;
|
||||
@ -178,11 +210,13 @@ void librtc_callback_client_audio_sender_data(const void* callback_data_ptr, con
|
||||
}
|
||||
|
||||
static NativeCallbacks native_callbacks{
|
||||
.version = 1,
|
||||
.version = 2,
|
||||
|
||||
.log = librtc_callback_log,
|
||||
.free_client_data = librtc_callback_free_client_data,
|
||||
|
||||
.rtc_configure = librtc_callback_rtc_configure,
|
||||
|
||||
.client_stream_assignment = librtc_callback_client_stream_assignment,
|
||||
.client_offer_generated = librtc_callback_client_offer_generated,
|
||||
|
||||
@ -213,12 +247,28 @@ Server::~Server() {
|
||||
librtc_destroy_server(this->server_ptr);
|
||||
}
|
||||
|
||||
RTCClientId Server::create_rtp_client(const std::shared_ptr<server::SpeakingClient> &client) {
|
||||
RTCClientId Server::create_rtp_client(const std::shared_ptr<server::SpeakingClient> &client, std::string& error) {
|
||||
auto data = new LibCallbackData{
|
||||
.client_id = client->getClientId(),
|
||||
.weak_ref = client
|
||||
};
|
||||
return librtc_create_rtp_client(this->server_ptr, data);
|
||||
|
||||
const char* error_ptr{nullptr};
|
||||
auto client_id = librtc_create_rtp_client(this->server_ptr, data, &error_ptr);
|
||||
if(client_id == 0) {
|
||||
/* LibCallbackData will be automatically freed */
|
||||
|
||||
if(error_ptr) {
|
||||
error.clear();
|
||||
error.append(error_ptr);
|
||||
librtc_free_str(error_ptr);
|
||||
} else {
|
||||
error = "unknown error";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return client_id;
|
||||
}
|
||||
|
||||
RTCClientId Server::create_native_client(const std::shared_ptr<server::SpeakingClient> &client) {
|
||||
|
@ -38,7 +38,7 @@ namespace ts::rtc {
|
||||
Server();
|
||||
~Server();
|
||||
|
||||
RTCClientId create_rtp_client(const std::shared_ptr<server::SpeakingClient>& /* client */);
|
||||
RTCClientId create_rtp_client(const std::shared_ptr<server::SpeakingClient>& /* client */, std::string& /* error */);
|
||||
RTCClientId create_native_client(const std::shared_ptr<server::SpeakingClient>& /* client */);
|
||||
void destroy_client(RTCClientId /* client id */);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user