#pragma once #include #include #include #include "mtx/events/voip.hpp" typedef struct _GstElement GstElement; class WebRTCSession : public QObject { Q_OBJECT public: enum class State { DISCONNECTED, INITIATING, INITIATED, OFFERSENT, CONNECTING, CONNECTED }; static WebRTCSession& instance() { static WebRTCSession instance; return instance; } bool init(std::string *errorMessage = nullptr); bool createOffer(); bool acceptOffer(const std::string &sdp); bool acceptAnswer(const std::string &sdp); void acceptICECandidates(const std::vector&); State state() const {return state_;} bool toggleMuteAudioSrc(bool &isMuted); void end(); void setStunServer(const std::string &stunServer) {stunServer_ = stunServer;} void setTurnServers(const std::vector &uris) {turnServers_ = uris;} signals: void offerCreated(const std::string &sdp, const std::vector&); void answerCreated(const std::string &sdp, const std::vector&); void stateChanged(WebRTCSession::State); // explicit qualifier necessary for Qt private slots: void setState(State state) {state_ = state;} private: WebRTCSession(); bool initialised_ = false; State state_ = State::DISCONNECTED; GstElement *pipe_ = nullptr; GstElement *webrtc_ = nullptr; std::string stunServer_; std::vector turnServers_; bool startPipeline(int opusPayloadType); bool createPipeline(int opusPayloadType); public: WebRTCSession(WebRTCSession const&) = delete; void operator=(WebRTCSession const&) = delete; };