summary refs log tree commit diff
path: root/src/voip/CallManager.h
diff options
context:
space:
mode:
authorRohit Sutradhar <rohitsutradhar311@gmail.com>2022-10-14 19:19:05 +0530
committerGitHub <noreply@github.com>2022-10-14 13:49:05 +0000
commitac48c332867e773e0e0eb9ad0139b7b625e26851 (patch)
tree9f4799c650889bb770f72e127441426c9ae42a07 /src/voip/CallManager.h
parentAdd toggle to disable decrypting notifications (diff)
downloadnheko-ac48c332867e773e0e0eb9ad0139b7b625e26851.tar.xz
VoIP v1 implementation (#1161)
* Initial commit for VoIP v1 implementation

* Added draft of event handlers for voip methods

* Added event handlers for VoIP events, added rejectCall, added version tracking for call version for V0 and V1 compatibility

* Added call events to the general message pipeline. Modified Call Reject mechanism

* Added message delegates for new events. Modified hidden events. Updated handle events.

* Updated implementation to keep track of calls on other devices

* Fixed linting

* Fixed code warnings

* Fixed minor bugs

* fixed ci

* Added acceptNegotiation method definition when missing gstreamer

* Fixed warnings

* Fixed linting
Diffstat (limited to 'src/voip/CallManager.h')
-rw-r--r--src/voip/CallManager.h37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/voip/CallManager.h b/src/voip/CallManager.h
index 8f1615f8..3011444f 100644
--- a/src/voip/CallManager.h
+++ b/src/voip/CallManager.h
@@ -18,6 +18,7 @@
 #include "WebRTCSession.h"
 #include "mtx/events/collections.hpp"
 #include "mtx/events/voip.hpp"
+#include <mtxclient/utils.hpp>
 
 namespace mtx::responses {
 struct TurnServer;
@@ -30,6 +31,7 @@ class CallManager final : public QObject
     Q_OBJECT
     Q_PROPERTY(bool haveCallInvite READ haveCallInvite NOTIFY newInviteState)
     Q_PROPERTY(bool isOnCall READ isOnCall NOTIFY newCallState)
+    Q_PROPERTY(bool isOnCallOnOtherDevice READ isOnCallOnOtherDevice NOTIFY newCallDeviceState)
     Q_PROPERTY(webrtc::CallType callType READ callType NOTIFY newInviteState)
     Q_PROPERTY(webrtc::State callState READ callState NOTIFY newCallState)
     Q_PROPERTY(QString callParty READ callParty NOTIFY newInviteState)
@@ -46,7 +48,9 @@ public:
     CallManager(QObject *);
 
     bool haveCallInvite() const { return haveCallInvite_; }
-    bool isOnCall() const { return session_.state() != webrtc::State::DISCONNECTED; }
+    bool isOnCall() const { return (session_.state() != webrtc::State::DISCONNECTED); }
+    bool isOnCallOnOtherDevice() const { return (isOnCallOnOtherDevice_ != ""); }
+    bool checkSharesRoom(QString roomid_, std::string invitee) const;
     webrtc::CallType callType() const { return callType_; }
     webrtc::State callState() const { return session_.state(); }
     QString callParty() const { return callParty_; }
@@ -67,8 +71,9 @@ public slots:
     void toggleMicMute();
     void toggleLocalPiP() { session_.toggleLocalPiP(); }
     void acceptInvite();
-    void
-      hangUp(mtx::events::voip::CallHangUp::Reason = mtx::events::voip::CallHangUp::Reason::User);
+    void hangUp(
+      mtx::events::voip::CallHangUp::Reason = mtx::events::voip::CallHangUp::Reason::UserHangUp);
+    void rejectInvite();
     QStringList windowList();
     void previewWindow(unsigned int windowIndex) const;
 
@@ -77,8 +82,12 @@ signals:
     void newMessage(const QString &roomid, const mtx::events::voip::CallCandidates &);
     void newMessage(const QString &roomid, const mtx::events::voip::CallAnswer &);
     void newMessage(const QString &roomid, const mtx::events::voip::CallHangUp &);
+    void newMessage(const QString &roomid, const mtx::events::voip::CallSelectAnswer &);
+    void newMessage(const QString &roomid, const mtx::events::voip::CallReject &);
+    void newMessage(const QString &roomid, const mtx::events::voip::CallNegotiate &);
     void newInviteState();
     void newCallState();
+    void newCallDeviceState();
     void micMuteChanged();
     void devicesChanged();
     void turnServerRetrieved(const mtx::responses::TurnServer &);
@@ -92,18 +101,23 @@ private:
     QString callParty_;
     QString callPartyDisplayName_;
     QString callPartyAvatarUrl_;
+    std::string callPartyVersion_ = "1";
     std::string callid_;
-    std::string partyid_       = "";
-    std::string invitee_       = "";
-    const uint32_t timeoutms_  = 120000;
-    webrtc::CallType callType_ = webrtc::CallType::VOICE;
-    bool haveCallInvite_       = false;
+    std::string partyid_               = mtx::client::utils::random_token(8, false);
+    std::string selectedpartyid_       = "";
+    std::string invitee_               = "";
+    const uint32_t timeoutms_          = 120000;
+    webrtc::CallType callType_         = webrtc::CallType::VOICE;
+    bool haveCallInvite_               = false;
+    bool answerSelected_               = false;
+    std::string isOnCallOnOtherDevice_ = "";
     std::string inviteSDP_;
     std::vector<mtx::events::voip::CallCandidates::Candidate> remoteICECandidates_;
     std::vector<std::string> turnURIs_;
     QTimer turnServerTimer_;
     QMediaPlayer player_;
     std::vector<std::pair<QString, uint32_t>> windows_;
+    std::vector<std::string> rejectCallPartyIDs_;
 
     template<typename T>
     bool handleEvent(const mtx::events::collections::TimelineEvents &event);
@@ -111,11 +125,14 @@ private:
     void handleEvent(const mtx::events::RoomEvent<mtx::events::voip::CallCandidates> &);
     void handleEvent(const mtx::events::RoomEvent<mtx::events::voip::CallAnswer> &);
     void handleEvent(const mtx::events::RoomEvent<mtx::events::voip::CallHangUp> &);
+    void handleEvent(const mtx::events::RoomEvent<mtx::events::voip::CallSelectAnswer> &);
+    void handleEvent(const mtx::events::RoomEvent<mtx::events::voip::CallReject> &);
+    void handleEvent(const mtx::events::RoomEvent<mtx::events::voip::CallNegotiate> &);
     void answerInvite(const mtx::events::voip::CallInvite &, bool isVideo);
     void generateCallID();
     QStringList devices(bool isVideo) const;
-    void clear();
-    void endCall();
+    void clear(bool endAllCalls = true);
+    void endCall(bool endAllCalls = true);
     void playRingtone(const QUrl &ringtone, bool repeat);
     void stopRingtone();
 };