#pragma once #include #include #include namespace ts { namespace server { class WebClient; } namespace web { class VoiceBridge { public: typedef std::function cb_voice_data; typedef std::function cb_ice_candidate; typedef std::function cb_ice_candidate_finish; typedef std::function cb_initialized; typedef std::function cb_failed; std::shared_ptr voice_channel() { return this->_voice_channel; } explicit VoiceBridge(const std::shared_ptr&); virtual ~VoiceBridge(); bool initialize(std::string&); bool parse_offer(const std::string&); int apply_ice(const std::deque>& /* 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 owner(); void handle_media_stream(const std::shared_ptr& /* stream */); void handle_data_channel(const std::shared_ptr & /* channel */); void handle_audio_data(const std::shared_ptr& /* channel */, const pipes::buffer_view& /* buffer */, size_t /* payload offset */); std::weak_ptr _owner; std::chrono::system_clock::time_point offer_timestamp; std::unique_ptr connection; std::shared_ptr _voice_channel; std::weak_ptr _audio_channel; struct { uint16_t packet_id = 0; bool muted = true; } voice; bool negotiation_possible = false; bool negotiation_required = false; }; } }