matrixion/src/CallManager.h

72 lines
2.3 KiB
C
Raw Normal View History

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 <QSharedPointer>
#include <QString>
#include <QTimer>
#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
class UserSettings;
class WebRTCSession;
class CallManager : public QObject
{
Q_OBJECT
public:
CallManager(QSharedPointer<UserSettings>);
void sendInvite(const QString &roomid);
2020-08-01 21:31:10 +03:00
void hangUp(
mtx::events::msg::CallHangUp::Reason = mtx::events::msg::CallHangUp::Reason::User);
2020-07-11 02:19:48 +03:00
bool onActiveCall();
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);
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 &);
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_;
std::string callid_;
const uint32_t timeoutms_ = 120000;
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_;
QSharedPointer<UserSettings> settings_;
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> &);
void answerInvite(const mtx::events::msg::CallInvite &);
2020-07-11 02:19:48 +03:00
void generateCallID();
2020-08-01 21:31:10 +03:00
void clear();
2020-07-11 02:19:48 +03:00
void endCall();
void playRingtone(const QString &ringtone, bool repeat);
void stopRingtone();
};