2020-07-11 02:19:48 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
#include "mtx/events/voip.hpp"
|
|
|
|
|
2020-08-06 00:56:44 +03:00
|
|
|
typedef struct _GList GList;
|
2020-07-11 02:19:48 +03:00
|
|
|
typedef struct _GstElement GstElement;
|
|
|
|
|
|
|
|
class WebRTCSession : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-08-01 21:31:10 +03:00
|
|
|
enum class State
|
|
|
|
{
|
|
|
|
DISCONNECTED,
|
|
|
|
ICEFAILED,
|
|
|
|
INITIATING,
|
|
|
|
INITIATED,
|
|
|
|
OFFERSENT,
|
|
|
|
ANSWERSENT,
|
|
|
|
CONNECTING,
|
|
|
|
CONNECTED
|
2020-07-23 04:15:45 +03:00
|
|
|
};
|
|
|
|
|
2020-08-01 21:31:10 +03:00
|
|
|
static WebRTCSession &instance()
|
2020-07-11 02:19:48 +03:00
|
|
|
{
|
2020-08-01 21:31:10 +03:00
|
|
|
static WebRTCSession instance;
|
|
|
|
return instance;
|
2020-07-11 02:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool init(std::string *errorMessage = nullptr);
|
2020-08-01 21:31:10 +03:00
|
|
|
State state() const { return state_; }
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
bool createOffer();
|
|
|
|
bool acceptOffer(const std::string &sdp);
|
|
|
|
bool acceptAnswer(const std::string &sdp);
|
2020-08-01 21:31:10 +03:00
|
|
|
void acceptICECandidates(const std::vector<mtx::events::msg::CallCandidates::Candidate> &);
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
bool toggleMuteAudioSrc(bool &isMuted);
|
|
|
|
void end();
|
|
|
|
|
2020-08-01 21:31:10 +03:00
|
|
|
void setStunServer(const std::string &stunServer) { stunServer_ = stunServer; }
|
|
|
|
void setTurnServers(const std::vector<std::string> &uris) { turnServers_ = uris; }
|
2020-07-11 02:19:48 +03:00
|
|
|
|
2020-08-06 00:56:44 +03:00
|
|
|
std::vector<std::string> getAudioSourceNames(const std::string &defaultDevice);
|
|
|
|
void setAudioSource(int audioDeviceIndex) { audioSourceIndex_ = audioDeviceIndex; }
|
|
|
|
|
2020-07-11 02:19:48 +03:00
|
|
|
signals:
|
2020-08-01 21:31:10 +03:00
|
|
|
void offerCreated(const std::string &sdp,
|
|
|
|
const std::vector<mtx::events::msg::CallCandidates::Candidate> &);
|
|
|
|
void answerCreated(const std::string &sdp,
|
|
|
|
const std::vector<mtx::events::msg::CallCandidates::Candidate> &);
|
|
|
|
void newICECandidate(const mtx::events::msg::CallCandidates::Candidate &);
|
2020-07-23 04:15:45 +03:00
|
|
|
void stateChanged(WebRTCSession::State); // explicit qualifier necessary for Qt
|
|
|
|
|
|
|
|
private slots:
|
2020-08-01 21:31:10 +03:00
|
|
|
void setState(State state) { state_ = state; }
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
private:
|
2020-07-23 04:15:45 +03:00
|
|
|
WebRTCSession();
|
2020-07-11 02:19:48 +03:00
|
|
|
|
2020-08-01 21:31:10 +03:00
|
|
|
bool initialised_ = false;
|
|
|
|
State state_ = State::DISCONNECTED;
|
|
|
|
GstElement *pipe_ = nullptr;
|
2020-07-11 02:19:48 +03:00
|
|
|
GstElement *webrtc_ = nullptr;
|
|
|
|
std::string stunServer_;
|
|
|
|
std::vector<std::string> turnServers_;
|
2020-08-06 00:56:44 +03:00
|
|
|
GList *audioSources_ = nullptr;
|
|
|
|
int audioSourceIndex_ = -1;
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
bool startPipeline(int opusPayloadType);
|
|
|
|
bool createPipeline(int opusPayloadType);
|
2020-08-06 00:56:44 +03:00
|
|
|
void refreshDevices();
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
public:
|
2020-08-01 21:31:10 +03:00
|
|
|
WebRTCSession(WebRTCSession const &) = delete;
|
|
|
|
void operator=(WebRTCSession const &) = delete;
|
2020-07-11 02:19:48 +03:00
|
|
|
};
|