2020-04-19 17:21:30 +02:00

59 lines
2.6 KiB
C++

#pragma once
#include <pipes/rtc/PeerConnection.h>
#include <pipes/rtc/channels/ApplicationChannel.h>
#include <pipes/rtc/channels/AudioChannel.h>
namespace ts {
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(const std::string& /* sdpMid */, int /* sdpMLineIndex */)> 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:
static void callback_log(void* ptr, pipes::Logger::LogLevel level, const std::string& name, const std::string& message, ...);
inline int server_id();
inline std::shared_ptr<server::WebClient> owner();
void handle_media_stream(const std::shared_ptr<rtc::Channel>& /* stream */);
void handle_data_channel(const std::shared_ptr<rtc::DataChannel> & /* channel */);
void handle_audio_data(const std::shared_ptr<rtc::MediaChannel>& /* 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::AudioChannel> _audio_channel;
struct {
uint16_t packet_id = 0;
bool muted = true;
} voice;
};
}
}