diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-10-04 14:41:48 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-10-04 14:49:04 +0900 |
commit | 50cc85d3dea93735fe352831421eea2fcf9c24c5 (patch) | |
tree | 7aa91a3da084058a8fdd87ca9f72ed313eac79ec /lib/room.cpp | |
parent | 5f2b4caa9b9cd63e1652d6550ceebecdb52df424 (diff) | |
download | libquotient-50cc85d3dea93735fe352831421eea2fcf9c24c5.tar.gz libquotient-50cc85d3dea93735fe352831421eea2fcf9c24c5.zip |
Modernise and fix code dealing with call events
Call events no more store deserialised values; instead they deserialise
values on the fly, same as all other events. They are no more treated as
state events (The Spec doesn't define them as state events in the first
place). A common base class, CallEventBase, is introduced that defines
data pieces common to all call events (call id and version).
Diffstat (limited to 'lib/room.cpp')
-rw-r--r-- | lib/room.cpp | 62 |
1 files changed, 19 insertions, 43 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index ee2e2b8e..2253c636 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1300,58 +1300,42 @@ bool isEchoEvent(const RoomEventPtr& le, const PendingEventItem& re) return le->contentJson() == re->contentJson(); } -bool Room::processCall(Room* room, const RoomEvent* event) -{ - if (!room->isCallSupported()) { - qCDebug(MAIN) << "Got call event in room with more then two" - << "members, Ignoring this event!"; - return false; - } - emit callEvent(room, event); - return false; -} - -bool Room::isCallSupported() const +bool Room::supportsCalls() const { return d->membersMap.size() == 2; } void Room::inviteCall(const QString& callId, const int lifetime, - const QString& sdp) + const QString& sdp) { - Q_ASSERT(isCallSupported()); - auto *evt = new CallInviteEvent(callId, lifetime, sdp); - postEvent(evt); + Q_ASSERT(supportsCalls()); + postEvent(new CallInviteEvent(callId, lifetime, sdp)); } -void Room::callCandidates(const QString& callId, - const QJsonArray& candidates) +void Room::sendCallCandidates(const QString& callId, + const QJsonArray& candidates) { - Q_ASSERT(isCallSupported()); - auto *evt = new CallCandidatesEvent(callId, candidates); - postEvent(evt); + Q_ASSERT(supportsCalls()); + postEvent(new CallCandidatesEvent(callId, candidates)); } void Room::answerCall(const QString& callId, const int lifetime, - const QString& sdp) + const QString& sdp) { - Q_ASSERT(isCallSupported()); - auto *evt = new CallAnswerEvent(callId, lifetime, sdp); - postEvent(evt); + Q_ASSERT(supportsCalls()); + postEvent(new CallAnswerEvent(callId, lifetime, sdp)); } void Room::answerCall(const QString& callId, const QString& sdp) { - Q_ASSERT(isCallSupported()); - auto *evt = new CallAnswerEvent(callId, sdp); - postEvent(evt); + Q_ASSERT(supportsCalls()); + postEvent(new CallAnswerEvent(callId, sdp)); } void Room::hangupCall(const QString& callId) { - Q_ASSERT(isCallSupported()); - auto *evt = new CallHangupEvent(callId); - postEvent(evt); + Q_ASSERT(supportsCalls()); + postEvent(new CallHangupEvent(callId)); } void Room::getPreviousContent(int limit) @@ -1701,6 +1685,10 @@ void Room::Private::addNewMessageEvents(RoomEvents&& events) } emit q->pendingEventMerged(); } + if (q->supportsCalls()) + for (const auto& evt: RoomEventsRange(events.begin(), newEnd)) + if (evt->isCallEvent()) + emit q->callEvent(q, weakPtrCast<CallEventBase>(evt)); if (totalInserted > 0) { @@ -1829,18 +1817,6 @@ bool Room::processStateEvent(const RoomEvent& e) } return false; } - , [this] (const CallAnswerEvent& evt) { - return processCall(this, &evt); - } - , [this] (const CallCandidatesEvent& evt) { - return processCall(this, &evt); - } - , [this] (const CallHangupEvent& evt) { - return processCall(this, &evt); - } - , [this] (const CallInviteEvent& evt) { - return processCall(this, &evt); - } , [this] (const EncryptionEvent& evt) { d->encryptionAlgorithm = evt.algorithm(); qCDebug(MAIN) << "Encryption switched on in room" << id() |