59 lines
2.6 KiB
C
Raw Normal View History

#pragma once
#include <pipes/rtc/PeerConnection.h>
2020-03-25 20:36:44 +01:00
#include <pipes/rtc/channels/ApplicationChannel.h>
#include <pipes/rtc/channels/AudioChannel.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;
2020-04-19 17:21:30 +02:00
typedef std::function<void(const std::string& /* sdpMid */, int /* sdpMLineIndex */)> cb_ice_candidate_finish;
2020-01-24 02:57:58 +01:00
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:
2020-03-25 20:36:44 +01:00
static void callback_log(void* ptr, pipes::Logger::LogLevel level, const std::string& name, const std::string& message, ...);
2020-01-24 02:57:58 +01:00
inline int server_id();
inline std::shared_ptr<server::WebClient> owner();
2020-03-25 20:36:44 +01:00
void handle_media_stream(const std::shared_ptr<rtc::Channel>& /* stream */);
2020-01-24 02:57:58 +01:00
void handle_data_channel(const std::shared_ptr<rtc::DataChannel> & /* channel */);
2020-03-25 20:36:44 +01:00
void handle_audio_data(const std::shared_ptr<rtc::MediaChannel>& /* channel */, const pipes::buffer_view& /* buffer */, size_t /* payload offset */);
2020-01-24 02:57:58 +01:00
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;
2020-03-25 20:36:44 +01:00
std::weak_ptr<rtc::AudioChannel> _audio_channel;
2020-01-24 02:57:58 +01:00
struct {
uint16_t packet_id = 0;
bool muted = true;
} voice;
};
}
}