2020-07-11 02:19:48 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <QMediaPlayer>
|
2020-08-01 21:31:10 +03:00
|
|
|
#include <QObject>
|
2020-07-11 02:19:48 +03:00
|
|
|
#include <QString>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2020-12-10 04:49:48 +03:00
|
|
|
#include "WebRTCSession.h"
|
2020-07-11 02:19:48 +03:00
|
|
|
#include "mtx/events/collections.hpp"
|
|
|
|
#include "mtx/events/voip.hpp"
|
2020-07-26 17:59:50 +03:00
|
|
|
|
|
|
|
namespace mtx::responses {
|
|
|
|
struct TurnServer;
|
|
|
|
}
|
2020-07-11 02:19:48 +03:00
|
|
|
|
2020-12-17 19:25:32 +03:00
|
|
|
class QStringList;
|
2020-11-13 03:55:35 +03:00
|
|
|
class QUrl;
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
class CallManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-12-17 19:25:32 +03:00
|
|
|
Q_PROPERTY(bool haveCallInvite READ haveCallInvite NOTIFY newInviteState)
|
2020-12-10 04:49:48 +03:00
|
|
|
Q_PROPERTY(bool isOnCall READ isOnCall NOTIFY newCallState)
|
2020-12-17 19:25:32 +03:00
|
|
|
Q_PROPERTY(bool isVideo READ isVideo NOTIFY newInviteState)
|
2020-12-10 04:49:48 +03:00
|
|
|
Q_PROPERTY(webrtc::State callState READ callState NOTIFY newCallState)
|
2020-12-17 19:25:32 +03:00
|
|
|
Q_PROPERTY(QString callParty READ callParty NOTIFY newInviteState)
|
|
|
|
Q_PROPERTY(QString callPartyAvatarUrl READ callPartyAvatarUrl NOTIFY newInviteState)
|
2020-12-10 04:49:48 +03:00
|
|
|
Q_PROPERTY(bool isMicMuted READ isMicMuted NOTIFY micMuteChanged)
|
|
|
|
Q_PROPERTY(bool callsSupported READ callsSupported CONSTANT)
|
2020-12-17 19:25:32 +03:00
|
|
|
Q_PROPERTY(QStringList mics READ mics NOTIFY devicesChanged)
|
|
|
|
Q_PROPERTY(QStringList cameras READ cameras NOTIFY devicesChanged)
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
public:
|
2020-10-28 23:08:17 +03:00
|
|
|
CallManager(QObject *);
|
2020-07-11 02:19:48 +03:00
|
|
|
|
2020-10-27 20:14:06 +03:00
|
|
|
void sendInvite(const QString &roomid, bool isVideo);
|
2020-12-17 19:25:32 +03:00
|
|
|
bool haveCallInvite() const { return haveCallInvite_; }
|
2020-12-10 04:49:48 +03:00
|
|
|
bool isOnCall() const { return session_.state() != webrtc::State::DISCONNECTED; }
|
2020-12-17 19:25:32 +03:00
|
|
|
bool isVideo() const { return isVideo_; }
|
2020-12-10 04:49:48 +03:00
|
|
|
webrtc::State callState() const { return session_.state(); }
|
2020-12-17 19:25:32 +03:00
|
|
|
QString callParty() const { return callParty_; }
|
2020-09-25 17:26:36 +03:00
|
|
|
QString callPartyAvatarUrl() const { return callPartyAvatarUrl_; }
|
2020-12-10 04:49:48 +03:00
|
|
|
bool isMicMuted() const { return session_.isMicMuted(); }
|
|
|
|
bool callsSupported() const;
|
2020-12-17 19:25:32 +03:00
|
|
|
QStringList mics() const { return devices(false); }
|
|
|
|
QStringList cameras() const { return devices(true); }
|
2020-07-31 02:59:54 +03:00
|
|
|
void refreshTurnServer();
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void syncEvent(const mtx::events::collections::TimelineEvents &event);
|
2020-12-10 04:49:48 +03:00
|
|
|
void toggleMicMute();
|
|
|
|
void toggleCameraView() { session_.toggleCameraView(); }
|
2020-12-17 19:25:32 +03:00
|
|
|
void acceptInvite();
|
|
|
|
void hangUp(
|
|
|
|
mtx::events::msg::CallHangUp::Reason = mtx::events::msg::CallHangUp::Reason::User);
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
signals:
|
2020-08-01 21:31:10 +03:00
|
|
|
void newMessage(const QString &roomid, const mtx::events::msg::CallInvite &);
|
|
|
|
void newMessage(const QString &roomid, const mtx::events::msg::CallCandidates &);
|
|
|
|
void newMessage(const QString &roomid, const mtx::events::msg::CallAnswer &);
|
|
|
|
void newMessage(const QString &roomid, const mtx::events::msg::CallHangUp &);
|
2020-12-17 19:25:32 +03:00
|
|
|
void newInviteState();
|
2020-12-10 04:49:48 +03:00
|
|
|
void newCallState();
|
|
|
|
void micMuteChanged();
|
2020-12-17 19:25:32 +03:00
|
|
|
void devicesChanged();
|
2020-08-01 21:31:10 +03:00
|
|
|
void turnServerRetrieved(const mtx::responses::TurnServer &);
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void retrieveTurnServer();
|
|
|
|
|
|
|
|
private:
|
2020-08-01 21:31:10 +03:00
|
|
|
WebRTCSession &session_;
|
2020-07-11 02:19:48 +03:00
|
|
|
QString roomid_;
|
2020-12-17 19:25:32 +03:00
|
|
|
QString callParty_;
|
2020-09-25 17:26:36 +03:00
|
|
|
QString callPartyAvatarUrl_;
|
2020-07-11 02:19:48 +03:00
|
|
|
std::string callid_;
|
|
|
|
const uint32_t timeoutms_ = 120000;
|
2020-12-17 19:25:32 +03:00
|
|
|
bool isVideo_ = false;
|
|
|
|
bool haveCallInvite_ = false;
|
|
|
|
std::string inviteSDP_;
|
2020-07-11 02:19:48 +03:00
|
|
|
std::vector<mtx::events::msg::CallCandidates::Candidate> remoteICECandidates_;
|
2020-07-26 17:59:50 +03:00
|
|
|
std::vector<std::string> turnURIs_;
|
2020-07-11 02:19:48 +03:00
|
|
|
QTimer turnServerTimer_;
|
|
|
|
QMediaPlayer player_;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
bool handleEvent_(const mtx::events::collections::TimelineEvents &event);
|
2020-08-01 21:31:10 +03:00
|
|
|
void handleEvent(const mtx::events::RoomEvent<mtx::events::msg::CallInvite> &);
|
|
|
|
void handleEvent(const mtx::events::RoomEvent<mtx::events::msg::CallCandidates> &);
|
|
|
|
void handleEvent(const mtx::events::RoomEvent<mtx::events::msg::CallAnswer> &);
|
|
|
|
void handleEvent(const mtx::events::RoomEvent<mtx::events::msg::CallHangUp> &);
|
2020-10-27 20:14:06 +03:00
|
|
|
void answerInvite(const mtx::events::msg::CallInvite &, bool isVideo);
|
2020-07-11 02:19:48 +03:00
|
|
|
void generateCallID();
|
2020-12-17 19:25:32 +03:00
|
|
|
QStringList devices(bool isVideo) const;
|
2020-08-01 21:31:10 +03:00
|
|
|
void clear();
|
2020-07-11 02:19:48 +03:00
|
|
|
void endCall();
|
2020-11-13 03:55:35 +03:00
|
|
|
void playRingtone(const QUrl &ringtone, bool repeat);
|
2020-07-11 02:19:48 +03:00
|
|
|
void stopRingtone();
|
|
|
|
};
|