Fixed the web client

This commit is contained in:
WolverinDEV 2020-03-20 17:00:15 +01:00
parent c74804ccf5
commit 124844b9d4
2 changed files with 9 additions and 57 deletions

View File

@ -77,18 +77,16 @@ std::shared_ptr<server::WebClient> VoiceBridge::owner() {
bool VoiceBridge::initialize(std::string &error) { bool VoiceBridge::initialize(std::string &error) {
if(!this->connection->initialize(error)) return false; if(!this->connection->initialize(error)) return false;
this->connection->callback_ice_candidate = [&](const rtc::IceCandidate& candidate, bool last_candidate) { this->connection->callback_ice_candidate = [&](const rtc::IceCandidate& candidate) {
auto function_callback = this->callback_ice_candidate; if(candidate.is_finished_candidate()) {
if(auto callback{this->callback_ice_candidate}; callback)
if(function_callback) callback(candidate);
function_callback(candidate); } else {
if(last_candidate) { if(auto callback{this->callback_ice_candidate_finished}; callback)
auto function_callback_end = this->callback_ice_candidate_finished; callback();
this->negotiation_possible = true;
if(function_callback_end)
function_callback_end();
} }
}; };
this->connection->callback_new_stream = [&](const std::shared_ptr<rtc::Stream> &channel) { this->handle_media_stream(channel); }; //bind(&VoiceBridge::handle_media_stream, this, placeholders::_1); => crash this->connection->callback_new_stream = [&](const std::shared_ptr<rtc::Stream> &channel) { this->handle_media_stream(channel); }; //bind(&VoiceBridge::handle_media_stream, this, placeholders::_1); => crash
this->connection->callback_setup_fail = [&](rtc::PeerConnection::ConnectionComponent comp, const std::string& reason) { this->connection->callback_setup_fail = [&](rtc::PeerConnection::ConnectionComponent comp, const std::string& reason) {
debugMessage(this->server_id(), "{} WebRTC setup failed! Component {} ({})", CLIENT_STR_LOG_PREFIX_(this->owner()), comp, reason); debugMessage(this->server_id(), "{} WebRTC setup failed! Component {} ({})", CLIENT_STR_LOG_PREFIX_(this->owner()), comp, reason);
@ -109,12 +107,7 @@ int VoiceBridge::apply_ice(const std::deque<std::shared_ptr<rtc::IceCandidate>>&
} }
void VoiceBridge::remote_ice_finished() { void VoiceBridge::remote_ice_finished() {
if(negotiation_possible) { this->connection->remote_candidates_finished();
this->connection->execute_negotiation();
negotiation_required = false;
} else {
negotiation_required = true;
}
} }
std::string VoiceBridge::generate_answer() { std::string VoiceBridge::generate_answer() {
@ -128,10 +121,6 @@ void VoiceBridge::execute_tick() {
this->connection->callback_setup_fail(rtc::PeerConnection::ConnectionComponent::BASE, "setup timeout"); this->connection->callback_setup_fail(rtc::PeerConnection::ConnectionComponent::BASE, "setup timeout");
} }
} }
if(this->negotiation_required && this->negotiation_possible) {
this->connection->execute_negotiation();
negotiation_required = false;
}
} }
void VoiceBridge::handle_media_stream(const std::shared_ptr<rtc::Stream> &undefined_stream) { void VoiceBridge::handle_media_stream(const std::shared_ptr<rtc::Stream> &undefined_stream) {
@ -174,40 +163,6 @@ void VoiceBridge::handle_data_channel(const std::shared_ptr<rtc::DataChannel> &c
}; };
} }
/*
ssize_t sample_count = 960;
ssize_t sample_length = sample_count * 2;
opus_int16 samples[sample_length];
if(!this->decoder) {
int error;
this->decoder = opus_decoder_create(48000, 2, &error);
assert(error == 0 && this->decoder);
}
if(!this->encoder) {
int error;
this->encoder = opus_encoder_create(48000, 2, OPUS_APPLICATION_AUDIO, &error);
assert(error == 0 && this->encoder);
}
{
sample_count = opus_decode(this->decoder, (u_char*) &data.data()[payload_offset], data.length() - payload_offset, samples, sample_count, 0);
if(sample_count < 0) {
logError(this->server_id(), "Could not decode opus!");
return;
}
}
string target_buffer(512, '\0'); //Way too big!
le2be16(this->voice.packet_id++, (char*) target_buffer.data());
target_buffer[2] = 5;
auto encoded = opus_encode(this->encoder, samples, sample_count, (u_char*) &target_buffer[3], 512 - 3);
if(encoded < 0 ){
logError(this->server_id(), "Could not encode opus!");
return;
}
*/
void VoiceBridge::handle_audio_data(const std::shared_ptr<rtc::AudioChannel> &channel, const pipes::buffer_view &data, size_t payload_offset) { void VoiceBridge::handle_audio_data(const std::shared_ptr<rtc::AudioChannel> &channel, const pipes::buffer_view &data, size_t payload_offset) {
if(channel->codec->type != rtc::codec::TypedAudio::OPUS) { if(channel->codec->type != rtc::codec::TypedAudio::OPUS) {
debugMessage(this->server_id(), "{} Got unknown codec ({})!", CLIENT_STR_LOG_PREFIX_(this->owner()), channel->codec->type); debugMessage(this->server_id(), "{} Got unknown codec ({})!", CLIENT_STR_LOG_PREFIX_(this->owner()), channel->codec->type);

View File

@ -53,9 +53,6 @@ namespace ts {
uint16_t packet_id = 0; uint16_t packet_id = 0;
bool muted = true; bool muted = true;
} voice; } voice;
bool negotiation_possible = false;
bool negotiation_required = false;
}; };
} }
} }