diff --git a/src/CallManager.cpp b/src/CallManager.cpp
index 89cfeaf9..cb523bc2 100644
--- a/src/CallManager.cpp
+++ b/src/CallManager.cpp
@@ -13,7 +13,6 @@
#include "MainWindow.h"
#include "MatrixClient.h"
#include "Utils.h"
-#include "WebRTCSession.h"
#include "dialogs/AcceptCall.h"
#include "mtx/responses/turn_server.hpp"
@@ -112,6 +111,7 @@ CallManager::CallManager(QObject *parent)
default:
break;
}
+ emit newCallState();
});
connect(&player_,
@@ -144,7 +144,7 @@ CallManager::CallManager(QObject *parent)
void
CallManager::sendInvite(const QString &roomid, bool isVideo)
{
- if (onActiveCall())
+ if (isOnCall())
return;
auto roomInfo = cache::singleRoomInfo(roomid.toStdString());
@@ -206,12 +206,6 @@ CallManager::hangUp(CallHangUp::Reason reason)
}
}
-bool
-CallManager::onActiveCall() const
-{
- return session_.state() != webrtc::State::DISCONNECTED;
-}
-
void
CallManager::syncEvent(const mtx::events::collections::TimelineEvents &event)
{
@@ -257,7 +251,7 @@ CallManager::handleEvent(const RoomEvent<CallInvite> &callInviteEvent)
return;
auto roomInfo = cache::singleRoomInfo(callInviteEvent.room_id);
- if (onActiveCall() || roomInfo.member_count != 2) {
+ if (isOnCall() || roomInfo.member_count != 2) {
emit newMessage(QString::fromStdString(callInviteEvent.room_id),
CallHangUp{callInviteEvent.content.call_id,
0,
@@ -332,7 +326,7 @@ CallManager::handleEvent(const RoomEvent<CallCandidates> &callCandidatesEvent)
callCandidatesEvent.sender);
if (callid_ == callCandidatesEvent.content.call_id) {
- if (onActiveCall())
+ if (isOnCall())
session_.acceptICECandidates(callCandidatesEvent.content.candidates);
else {
// CallInvite has been received and we're awaiting localUser to accept or
@@ -350,7 +344,7 @@ CallManager::handleEvent(const RoomEvent<CallAnswer> &callAnswerEvent)
callAnswerEvent.content.call_id,
callAnswerEvent.sender);
- if (!onActiveCall() && callAnswerEvent.sender == utils::localUser().toStdString() &&
+ if (!isOnCall() && callAnswerEvent.sender == utils::localUser().toStdString() &&
callid_ == callAnswerEvent.content.call_id) {
emit ChatPage::instance()->showNotification("Call answered on another device.");
stopRingtone();
@@ -358,7 +352,7 @@ CallManager::handleEvent(const RoomEvent<CallAnswer> &callAnswerEvent)
return;
}
- if (onActiveCall() && callid_ == callAnswerEvent.content.call_id) {
+ if (isOnCall() && callid_ == callAnswerEvent.content.call_id) {
stopRingtone();
if (!session_.acceptAnswer(callAnswerEvent.content.sdp)) {
emit ChatPage::instance()->showNotification("Problem setting up call.");
@@ -382,6 +376,23 @@ CallManager::handleEvent(const RoomEvent<CallHangUp> &callHangUpEvent)
}
void
+CallManager::toggleMicMute()
+{
+ session_.toggleMicMute();
+ emit micMuteChanged();
+}
+
+bool
+CallManager::callsSupported() const
+{
+#ifdef GSTREAMER_AVAILABLE
+ return true;
+#else
+ return false;
+#endif
+}
+
+void
CallManager::generateCallID()
{
using namespace std::chrono;
diff --git a/src/CallManager.h b/src/CallManager.h
index 8004e838..d59a6249 100644
--- a/src/CallManager.h
+++ b/src/CallManager.h
@@ -8,6 +8,7 @@
#include <QString>
#include <QTimer>
+#include "WebRTCSession.h"
#include "mtx/events/collections.hpp"
#include "mtx/events/voip.hpp"
@@ -16,11 +17,17 @@ struct TurnServer;
}
class QUrl;
-class WebRTCSession;
class CallManager : public QObject
{
Q_OBJECT
+ Q_PROPERTY(bool isOnCall READ isOnCall NOTIFY newCallState)
+ Q_PROPERTY(bool isOnVideoCall READ isOnVideoCall NOTIFY newVideoCallState)
+ Q_PROPERTY(webrtc::State callState READ callState NOTIFY newCallState)
+ Q_PROPERTY(QString callPartyName READ callPartyName NOTIFY newCallParty)
+ Q_PROPERTY(QString callPartyAvatarUrl READ callPartyAvatarUrl NOTIFY newCallParty)
+ Q_PROPERTY(bool isMicMuted READ isMicMuted NOTIFY micMuteChanged)
+ Q_PROPERTY(bool callsSupported READ callsSupported CONSTANT)
public:
CallManager(QObject *);
@@ -28,21 +35,29 @@ public:
void sendInvite(const QString &roomid, bool isVideo);
void hangUp(
mtx::events::msg::CallHangUp::Reason = mtx::events::msg::CallHangUp::Reason::User);
- bool onActiveCall() const;
+ bool isOnCall() const { return session_.state() != webrtc::State::DISCONNECTED; }
+ bool isOnVideoCall() const { return session_.isVideo(); }
+ webrtc::State callState() const { return session_.state(); }
QString callPartyName() const { return callPartyName_; }
QString callPartyAvatarUrl() const { return callPartyAvatarUrl_; }
+ bool isMicMuted() const { return session_.isMicMuted(); }
+ bool callsSupported() const;
void refreshTurnServer();
public slots:
void syncEvent(const mtx::events::collections::TimelineEvents &event);
+ void toggleMicMute();
+ void toggleCameraView() { session_.toggleCameraView(); }
signals:
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 newCallParty();
+ void newCallState();
void newVideoCallState();
+ void newCallParty();
+ void micMuteChanged();
void turnServerRetrieved(const mtx::responses::TurnServer &);
private slots:
diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp
index 5cbc33e0..2f50a7cc 100644
--- a/src/timeline/InputBar.cpp
+++ b/src/timeline/InputBar.cpp
@@ -597,7 +597,7 @@ void
InputBar::callButton()
{
auto callManager_ = ChatPage::instance()->callManager();
- if (callManager_->onActiveCall()) {
+ if (callManager_->isOnCall()) {
callManager_->hangUp();
} else {
auto current_room_ = room->roomId();
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index f10c2c0d..97af0065 100644
--- a/src/timeline/TimelineViewManager.cpp
+++ b/src/timeline/TimelineViewManager.cpp
@@ -136,6 +136,10 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
"im.nheko", 1, 0, "Settings", [](QQmlEngine *, QJSEngine *) -> QObject * {
return ChatPage::instance()->userSettings().data();
});
+ qmlRegisterSingletonType<CallManager>(
+ "im.nheko", 1, 0, "CallManager", [](QQmlEngine *, QJSEngine *) -> QObject * {
+ return ChatPage::instance()->callManager();
+ });
qRegisterMetaType<mtx::events::collections::TimelineEvents>();
qRegisterMetaType<std::vector<DeviceInfo>>();
@@ -237,36 +241,6 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
isInitialSync_ = true;
emit initialSyncChanged(true);
});
- connect(&WebRTCSession::instance(),
- &WebRTCSession::stateChanged,
- this,
- &TimelineViewManager::callStateChanged);
- connect(
- callManager_, &CallManager::newCallParty, this, &TimelineViewManager::callPartyChanged);
- connect(callManager_,
- &CallManager::newVideoCallState,
- this,
- &TimelineViewManager::videoCallChanged);
-
- connect(&WebRTCSession::instance(),
- &WebRTCSession::stateChanged,
- this,
- &TimelineViewManager::onCallChanged);
-}
-
-bool
-TimelineViewManager::isOnCall() const
-{
- return callManager_->onActiveCall();
-}
-bool
-TimelineViewManager::callsSupported() const
-{
-#ifdef GSTREAMER_AVAILABLE
- return true;
-#else
- return false;
-#endif
}
void
@@ -355,19 +329,6 @@ TimelineViewManager::escapeEmoji(QString str) const
}
void
-TimelineViewManager::toggleMicMute()
-{
- WebRTCSession::instance().toggleMicMute();
- emit micMuteChanged();
-}
-
-void
-TimelineViewManager::toggleCameraView()
-{
- WebRTCSession::instance().toggleCameraView();
-}
-
-void
TimelineViewManager::openImageOverlay(QString mxcUrl, QString eventId) const
{
if (mxcUrl.isEmpty()) {
diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h
index 1cec0939..23a960b8 100644
--- a/src/timeline/TimelineViewManager.h
+++ b/src/timeline/TimelineViewManager.h
@@ -36,13 +36,6 @@ class TimelineViewManager : public QObject
bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged)
Q_PROPERTY(
bool isNarrowView MEMBER isNarrowView_ READ isNarrowView NOTIFY narrowViewChanged)
- Q_PROPERTY(webrtc::State callState READ callState NOTIFY callStateChanged)
- Q_PROPERTY(bool onVideoCall READ onVideoCall NOTIFY videoCallChanged)
- Q_PROPERTY(QString callPartyName READ callPartyName NOTIFY callPartyChanged)
- Q_PROPERTY(QString callPartyAvatarUrl READ callPartyAvatarUrl NOTIFY callPartyChanged)
- Q_PROPERTY(bool isMicMuted READ isMicMuted NOTIFY micMuteChanged)
- Q_PROPERTY(bool isOnCall READ isOnCall NOTIFY onCallChanged)
- Q_PROPERTY(bool callsSupported READ callsSupported CONSTANT)
public:
TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr);
@@ -61,14 +54,6 @@ public:
Q_INVOKABLE TimelineModel *activeTimeline() const { return timeline_; }
Q_INVOKABLE bool isInitialSync() const { return isInitialSync_; }
bool isNarrowView() const { return isNarrowView_; }
- webrtc::State callState() const { return WebRTCSession::instance().state(); }
- bool onVideoCall() const { return WebRTCSession::instance().isVideo(); }
- Q_INVOKABLE void setVideoCallItem();
- QString callPartyName() const { return callManager_->callPartyName(); }
- QString callPartyAvatarUrl() const { return callManager_->callPartyAvatarUrl(); }
- bool isMicMuted() const { return WebRTCSession::instance().isMicMuted(); }
- Q_INVOKABLE void toggleMicMute();
- Q_INVOKABLE void toggleCameraView();
Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId) const;
Q_INVOKABLE QColor userColor(QString id, QColor background);
Q_INVOKABLE QString escapeEmoji(QString str) const;
@@ -98,11 +83,6 @@ signals:
void inviteUsers(QStringList users);
void showRoomList();
void narrowViewChanged();
- void callStateChanged(webrtc::State);
- void videoCallChanged();
- void callPartyChanged();
- void micMuteChanged();
- void onCallChanged();
public slots:
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
@@ -130,8 +110,7 @@ public slots:
void queueCallMessage(const QString &roomid, const mtx::events::msg::CallHangUp &);
void updateEncryptedDescriptions();
- bool isOnCall() const;
- bool callsSupported() const;
+ void setVideoCallItem();
void enableBackButton()
{
|