58 lines
2.4 KiB
C
Raw Normal View History

#pragma once
#include <pipes/rtc/PeerConnection.h>
#include <pipes/rtc/ApplicationStream.h>
#include <pipes/rtc/AudioStream.h>
namespace ts {
2020-01-24 02:57:58 +01:00
namespace server {
class WebClient;
}
namespace web {
class VoiceBridge {
public:
typedef std::function<void(const pipes::buffer_view&, bool, bool)> cb_voice_data;
typedef std::function<void(const rtc::IceCandidate&)> cb_ice_candidate;
typedef std::function<void()> cb_ice_candidate_finish;
typedef std::function<void()> cb_initialized;
typedef std::function<void()> cb_failed;
std::shared_ptr<rtc::DataChannel> voice_channel() { return this->_voice_channel; }
explicit VoiceBridge(const std::shared_ptr<server::WebClient>&);
virtual ~VoiceBridge();
bool initialize(std::string&);
bool parse_offer(const std::string&);
int apply_ice(const std::deque<std::shared_ptr<rtc::IceCandidate>>& /* candidates */);
void remote_ice_finished();
std::string generate_answer();
cb_ice_candidate callback_ice_candidate;
cb_ice_candidate_finish callback_ice_candidate_finished;
cb_voice_data callback_voice_data;
cb_initialized callback_initialized;
cb_failed callback_failed;
void execute_tick();
private:
inline int server_id();
inline std::shared_ptr<server::WebClient> owner();
void handle_media_stream(const std::shared_ptr<rtc::Stream>& /* stream */);
void handle_data_channel(const std::shared_ptr<rtc::DataChannel> & /* channel */);
void handle_audio_data(const std::shared_ptr<rtc::AudioChannel>& /* channel */, const pipes::buffer_view& /* buffer */, size_t /* payload offset */);
std::weak_ptr<server::WebClient> _owner;
std::chrono::system_clock::time_point offer_timestamp;
std::unique_ptr<rtc::PeerConnection> connection;
std::shared_ptr<rtc::DataChannel> _voice_channel;
std::weak_ptr<rtc::AudioStream> _audio_channel;
struct {
uint16_t packet_id = 0;
bool muted = true;
} voice;
};
}
}