summary refs log tree commit diff
path: root/src/CallManager.cpp
diff options
context:
space:
mode:
authortrilene <trilene@runbox.com>2020-10-27 13:14:06 -0400
committertrilene <trilene@runbox.com>2020-10-27 13:14:06 -0400
commitd1f3a3ef40a69fe50efe6e2b76400e7f5f5dfb6c (patch)
tree1d5eb5645f0aa410ddc22050d3bfb7459989e727 /src/CallManager.cpp
parentMerge branch 'master' of ssh://github.com/Nheko-Reborn/nheko (diff)
downloadnheko-d1f3a3ef40a69fe50efe6e2b76400e7f5f5dfb6c.tar.xz
Support video calls
Diffstat (limited to 'src/CallManager.cpp')
-rw-r--r--src/CallManager.cpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/CallManager.cpp b/src/CallManager.cpp
index b1d1a75a..4cd98a9f 100644
--- a/src/CallManager.cpp
+++ b/src/CallManager.cpp
@@ -25,9 +25,6 @@ Q_DECLARE_METATYPE(mtx::responses::TurnServer)
 using namespace mtx::events;
 using namespace mtx::events::msg;
 
-// https://github.com/vector-im/riot-web/issues/10173
-#define STUN_SERVER "stun://turn.matrix.org:3478"
-
 namespace {
 std::vector<std::string>
 getTurnURIs(const mtx::responses::TurnServer &turnServer);
@@ -43,6 +40,8 @@ CallManager::CallManager(QSharedPointer<UserSettings> userSettings)
         qRegisterMetaType<mtx::events::msg::CallCandidates::Candidate>();
         qRegisterMetaType<mtx::responses::TurnServer>();
 
+        session_.setSettings(userSettings);
+
         connect(
           &session_,
           &WebRTCSession::offerCreated,
@@ -128,30 +127,29 @@ CallManager::CallManager(QSharedPointer<UserSettings> userSettings)
 }
 
 void
-CallManager::sendInvite(const QString &roomid)
+CallManager::sendInvite(const QString &roomid, bool isVideo)
 {
         if (onActiveCall())
                 return;
 
         auto roomInfo = cache::singleRoomInfo(roomid.toStdString());
         if (roomInfo.member_count != 2) {
-                emit ChatPage::instance()->showNotification(
-                  "Voice calls are limited to 1:1 rooms.");
+                emit ChatPage::instance()->showNotification("Calls are limited to 1:1 rooms.");
                 return;
         }
 
         std::string errorMessage;
-        if (!session_.init(&errorMessage)) {
+        if (!session_.havePlugins(false, &errorMessage) ||
+            (isVideo && !session_.havePlugins(true, &errorMessage))) {
                 emit ChatPage::instance()->showNotification(QString::fromStdString(errorMessage));
                 return;
         }
 
         roomid_ = roomid;
-        session_.setStunServer(settings_->useStunServer() ? STUN_SERVER : "");
         session_.setTurnServers(turnURIs_);
-
         generateCallID();
-        nhlog::ui()->debug("WebRTC: call id: {} - creating invite", callid_);
+        nhlog::ui()->debug(
+          "WebRTC: call id: {} - creating {} invite", callid_, isVideo ? "video" : "voice");
         std::vector<RoomMember> members(cache::getMembers(roomid.toStdString()));
         const RoomMember &callee =
           members.front().user_id == utils::localUser() ? members.back() : members.front();
@@ -159,10 +157,12 @@ CallManager::sendInvite(const QString &roomid)
         callPartyAvatarUrl_ = QString::fromStdString(roomInfo.avatar_url);
         emit newCallParty();
         playRingtone("qrc:/media/media/ringback.ogg", true);
-        if (!session_.createOffer()) {
+        if (!session_.createOffer(isVideo)) {
                 emit ChatPage::instance()->showNotification("Problem setting up call.");
                 endCall();
         }
+        if (isVideo)
+                emit newVideoCallState();
 }
 
 namespace {
@@ -242,7 +242,7 @@ CallManager::handleEvent(const RoomEvent<CallInvite> &callInviteEvent)
                 return;
 
         auto roomInfo = cache::singleRoomInfo(callInviteEvent.room_id);
-        if (onActiveCall() || roomInfo.member_count != 2 || isVideo) {
+        if (onActiveCall() || roomInfo.member_count != 2) {
                 emit newMessage(QString::fromStdString(callInviteEvent.room_id),
                                 CallHangUp{callInviteEvent.content.call_id,
                                            0,
@@ -266,10 +266,11 @@ CallManager::handleEvent(const RoomEvent<CallInvite> &callInviteEvent)
                                               QString::fromStdString(roomInfo.name),
                                               QString::fromStdString(roomInfo.avatar_url),
                                               settings_,
+                                              isVideo,
                                               MainWindow::instance());
-        connect(dialog, &dialogs::AcceptCall::accept, this, [this, callInviteEvent]() {
+        connect(dialog, &dialogs::AcceptCall::accept, this, [this, callInviteEvent, isVideo]() {
                 MainWindow::instance()->hideOverlay();
-                answerInvite(callInviteEvent.content);
+                answerInvite(callInviteEvent.content, isVideo);
         });
         connect(dialog, &dialogs::AcceptCall::reject, this, [this]() {
                 MainWindow::instance()->hideOverlay();
@@ -279,19 +280,18 @@ CallManager::handleEvent(const RoomEvent<CallInvite> &callInviteEvent)
 }
 
 void
-CallManager::answerInvite(const CallInvite &invite)
+CallManager::answerInvite(const CallInvite &invite, bool isVideo)
 {
         stopRingtone();
         std::string errorMessage;
-        if (!session_.init(&errorMessage)) {
+        if (!session_.havePlugins(false, &errorMessage) ||
+            (isVideo && !session_.havePlugins(true, &errorMessage))) {
                 emit ChatPage::instance()->showNotification(QString::fromStdString(errorMessage));
                 hangUp();
                 return;
         }
 
-        session_.setStunServer(settings_->useStunServer() ? STUN_SERVER : "");
         session_.setTurnServers(turnURIs_);
-
         if (!session_.acceptOffer(invite.sdp)) {
                 emit ChatPage::instance()->showNotification("Problem setting up call.");
                 hangUp();
@@ -299,6 +299,8 @@ CallManager::answerInvite(const CallInvite &invite)
         }
         session_.acceptICECandidates(remoteICECandidates_);
         remoteICECandidates_.clear();
+        if (isVideo)
+                emit newVideoCallState();
 }
 
 void
@@ -384,7 +386,10 @@ CallManager::endCall()
 {
         stopRingtone();
         clear();
+        bool isVideo = session_.isVideo();
         session_.end();
+        if (isVideo)
+                emit newVideoCallState();
 }
 
 void