2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
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>
|
|
|
|
|
2021-02-07 19:47:47 +03:00
|
|
|
#include "CallDevices.h"
|
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)
|
2021-02-18 23:55:29 +03:00
|
|
|
Q_PROPERTY(webrtc::CallType callType READ callType 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)
|
2021-02-22 00:30:10 +03:00
|
|
|
Q_PROPERTY(bool haveLocalPiP READ haveLocalPiP NOTIFY newCallState)
|
2020-12-17 19:25:32 +03:00
|
|
|
Q_PROPERTY(QStringList mics READ mics NOTIFY devicesChanged)
|
|
|
|
Q_PROPERTY(QStringList cameras READ cameras NOTIFY devicesChanged)
|
2021-02-18 23:55:29 +03:00
|
|
|
Q_PROPERTY(bool callsSupported READ callsSupported CONSTANT)
|
|
|
|
Q_PROPERTY(bool screenShareSupported READ screenShareSupported CONSTANT)
|
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-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; }
|
2021-02-18 23:55:29 +03:00
|
|
|
webrtc::CallType callType() const { return callType_; }
|
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(); }
|
2021-02-22 00:30:10 +03:00
|
|
|
bool haveLocalPiP() const { return session_.haveLocalPiP(); }
|
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
|
|
|
|
2021-02-18 23:55:29 +03:00
|
|
|
static bool callsSupported();
|
|
|
|
static bool screenShareSupported();
|
|
|
|
|
2020-07-11 02:19:48 +03:00
|
|
|
public slots:
|
2021-02-25 01:07:01 +03:00
|
|
|
void sendInvite(const QString &roomid, webrtc::CallType, unsigned int windowIndex = 0);
|
2020-07-11 02:19:48 +03:00
|
|
|
void syncEvent(const mtx::events::collections::TimelineEvents &event);
|
2020-12-10 04:49:48 +03:00
|
|
|
void toggleMicMute();
|
2021-02-22 00:30:10 +03:00
|
|
|
void toggleLocalPiP() { session_.toggleLocalPiP(); }
|
2020-12-17 19:25:32 +03:00
|
|
|
void acceptInvite();
|
|
|
|
void hangUp(
|
|
|
|
mtx::events::msg::CallHangUp::Reason = mtx::events::msg::CallHangUp::Reason::User);
|
2021-02-25 01:07:01 +03:00
|
|
|
QStringList windowList();
|
2021-02-25 20:00:55 +03:00
|
|
|
void previewWindow(unsigned int windowIndex) const;
|
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_;
|
2021-02-18 23:55:29 +03:00
|
|
|
const uint32_t timeoutms_ = 120000;
|
|
|
|
webrtc::CallType callType_ = webrtc::CallType::VOICE;
|
|
|
|
bool haveCallInvite_ = false;
|
2020-12-17 19:25:32 +03:00
|
|
|
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_;
|
2021-02-25 01:07:01 +03:00
|
|
|
std::vector<std::pair<QString, uint32_t>> windows_;
|
2020-07-11 02:19:48 +03:00
|
|
|
|
|
|
|
template<typename T>
|
2021-02-25 20:00:55 +03:00
|
|
|
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();
|
|
|
|
};
|