diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connection.cpp | 10 | ||||
-rw-r--r-- | lib/connection.h | 2 | ||||
-rw-r--r-- | lib/events/callanswerevent.cpp | 76 | ||||
-rw-r--r-- | lib/events/callanswerevent.h | 66 | ||||
-rw-r--r-- | lib/events/callcandidatesevent.cpp | 69 | ||||
-rw-r--r-- | lib/events/callcandidatesevent.h | 56 | ||||
-rw-r--r-- | lib/events/callhangupevent.cpp | 59 | ||||
-rw-r--r-- | lib/events/callhangupevent.h | 52 | ||||
-rw-r--r-- | lib/events/callinviteevent.cpp | 68 | ||||
-rw-r--r-- | lib/events/callinviteevent.h | 63 | ||||
-rw-r--r-- | lib/jobs/turnserverjob.cpp | 58 | ||||
-rw-r--r-- | lib/jobs/turnserverjob.h | 40 | ||||
-rw-r--r-- | lib/room.cpp | 70 | ||||
-rw-r--r-- | lib/room.h | 14 |
14 files changed, 703 insertions, 0 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 017180c4..853b2a8a 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -34,6 +34,7 @@ #include "jobs/syncjob.h" #include "jobs/mediathumbnailjob.h" #include "jobs/downloadfilejob.h" +#include "jobs/turnserverjob.h" #include <QtNetwork/QDnsLookup> #include <QtCore/QFile> @@ -1189,3 +1190,12 @@ void Connection::setCacheState(bool newValue) emit cacheStateChanged(); } } + +void Connection::getTurnServers() +{ + auto job = callApi<TurnServerJob>(); + connect( job, &TurnServerJob::success, [=] { + emit turnServersChanged(job->toJson()); + }); + +} diff --git a/lib/connection.h b/lib/connection.h index 9b253711..238024aa 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -242,6 +242,7 @@ namespace QMatrixClient [[deprecated("Use accessToken() instead")]] Q_INVOKABLE QString token() const; + Q_INVOKABLE void getTurnServers(); /** * Call this before first sync to load from previously saved file. @@ -616,6 +617,7 @@ namespace QMatrixClient IgnoredUsersList removals); void cacheStateChanged(); + void turnServersChanged(const QJsonObject& servers); protected: /** diff --git a/lib/events/callanswerevent.cpp b/lib/events/callanswerevent.cpp new file mode 100644 index 00000000..14221bc1 --- /dev/null +++ b/lib/events/callanswerevent.cpp @@ -0,0 +1,76 @@ +/****************************************************************************** + * Copyright (C) 2017 Marius Gripsgard <marius@ubports.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "callanswerevent.h" + +#include "event.h" + +#include "logging.h" + +#include <QtCore/QJsonDocument> + +/* +m.call.answer +{ + "age": 242352, + "content": { + "answer": { + "sdp": "v=0\r\no=- 6584580628695956864 2 IN IP4 127.0.0.1[...]", + "type": "answer" + }, + "call_id": "12345", + "lifetime": 60000, + "version": 0 + }, + "event_id": "$WLGTSEFSEF:localhost", + "origin_server_ts": 1431961217939, + "room_id": "!Cuyf34gef24t:localhost", + "sender": "@example:localhost", + "type": "m.call.answer" +} +*/ + +using namespace QMatrixClient; + +CallAnswerEvent::CallAnswerEvent(const QJsonObject& obj) + : RoomEvent(CallAnswer, obj) + , _lifetime(contentJson()["lifetime"].toInt()) + , _sdp(contentJson()["answer"].toObject()["sdp"].toString()) + , _callId(contentJson()["call_id"].toString()) + , _version(contentJson()["version"].toInt()) +{ + qCDebug(EVENTS) << "Call Answer event"; +} + +CallAnswerEvent::CallAnswerEvent(const QString& callId, const int lifetime, + const QString& sdp) + : RoomEvent(CallAnswer) +{ + _version = 0; + _callId = callId; + _lifetime = lifetime; + _sdp = sdp; +} + +CallAnswerEvent::CallAnswerEvent(const QString& callId, const QString& sdp) + : RoomEvent(CallAnswer) +{ + _version = 0; + _callId = callId; + _sdp = sdp; +} diff --git a/lib/events/callanswerevent.h b/lib/events/callanswerevent.h new file mode 100644 index 00000000..b26a66c3 --- /dev/null +++ b/lib/events/callanswerevent.h @@ -0,0 +1,66 @@ +/****************************************************************************** + * Copyright (C) 2017 Marius Gripsgard <marius@ubports.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "roomevent.h" + +namespace QMatrixClient +{ + class CallAnswerEvent: public RoomEvent + { + public: + DEFINE_EVENT_TYPEID("m.call.answer", CallAnswerEvent) + + explicit CallAnswerEvent(const QJsonObject& obj); + + explicit CallAnswerEvent(const QString& callId, const int lifetime, + const QString& sdp); + explicit CallAnswerEvent(const QString& callId, const QString& sdp); + + const int lifetime() const { return _lifetime; } + const QString& sdp() const { return _sdp; } + const QString& callId() const { return _callId; } + const int version() const { return _version; } + + QJsonObject toJson() const + { + QJsonObject answer; + answer.insert("sdp", _sdp); + answer.insert("type", QStringLiteral("answer")); + + QJsonObject obj; + obj.insert("call_id", _callId); + obj.insert("version", _version); + if (_lifetime != NULL) + obj.insert("lifetime", _lifetime); + obj.insert("answer", answer); + return obj; + } + + private: + int _lifetime; + QJsonObject _answer; + QString _sdp; + QString _callId; + int _version; + }; + + REGISTER_EVENT_TYPE(CallAnswerEvent) + DEFINE_EVENTTYPE_ALIAS(CallAnswer, CallAnswerEvent) +} diff --git a/lib/events/callcandidatesevent.cpp b/lib/events/callcandidatesevent.cpp new file mode 100644 index 00000000..bf7f0f79 --- /dev/null +++ b/lib/events/callcandidatesevent.cpp @@ -0,0 +1,69 @@ +/****************************************************************************** + * Copyright (C) 2017 Marius Gripsgard <marius@ubports.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "callcandidatesevent.h" + +#include "event.h" + +#include "logging.h" + +#include <QtCore/QJsonDocument> + +/* +m.call.candidates +{ + "age": 242352, + "content": { + "call_id": "12345", + "candidates": [ + { + "candidate": "candidate:863018703 1 udp 2122260223 10.9.64.156 43670 typ host generation 0", + "sdpMLineIndex": 0, + "sdpMid": "audio" + } + ], + "version": 0 + }, + "event_id": "$WLGTSEFSEF:localhost", + "origin_server_ts": 1431961217939, + "room_id": "!Cuyf34gef24t:localhost", + "sender": "@example:localhost", + "type": "m.call.candidates" +} +*/ + +using namespace QMatrixClient; + + +CallCandidatesEvent::CallCandidatesEvent(const QJsonObject& obj) + : RoomEvent(CallCandidates, obj) + , _candidates(contentJson()["candidates"].toArray()) + , _callId(contentJson()["call_id"].toString()) + , _version(contentJson()["version"].toInt()) +{ + qCDebug(EVENTS) << "Call Candidates event"; +} + +CallCandidatesEvent::CallCandidatesEvent(const QString& callId, + const QJsonArray& candidates) + : RoomEvent(CallCandidates) +{ + _version = 0; + _callId = callId; + _candidates = candidates; +} diff --git a/lib/events/callcandidatesevent.h b/lib/events/callcandidatesevent.h new file mode 100644 index 00000000..fa2de993 --- /dev/null +++ b/lib/events/callcandidatesevent.h @@ -0,0 +1,56 @@ +/****************************************************************************** + * Copyright (C) 2017 Marius Gripsgard <marius@ubports.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "roomevent.h" + +namespace QMatrixClient +{ + class CallCandidatesEvent: public RoomEvent + { + public: + DEFINE_EVENT_TYPEID("m.call.candidates", CallCandidatesEvent) + + explicit CallCandidatesEvent(const QJsonObject& obj); + + explicit CallCandidatesEvent(const QString& callId, + const QJsonArray& candidates); + + const QJsonArray& candidates() const { return _candidates; } + const QString& callId() const { return _callId; } + const int version() const { return _version; } + + QJsonObject toJson() const + { + QJsonObject obj; + obj.insert("call_id", _callId); + obj.insert("version", _version); + obj.insert("candidates", _candidates); + return obj; + } + + private: + QJsonArray _candidates; + QString _callId; + int _version; + }; + + REGISTER_EVENT_TYPE(CallCandidatesEvent) + DEFINE_EVENTTYPE_ALIAS(CallCandidates, CallCandidatesEvent) +} diff --git a/lib/events/callhangupevent.cpp b/lib/events/callhangupevent.cpp new file mode 100644 index 00000000..e83f506f --- /dev/null +++ b/lib/events/callhangupevent.cpp @@ -0,0 +1,59 @@ +/****************************************************************************** + * Copyright (C) 2017 Marius Gripsgard <marius@ubports.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "callhangupevent.h" + +#include "event.h" + +#include "logging.h" + +#include <QtCore/QJsonDocument> + +/* +m.call.hangup +{ + "age": 242352, + "content": { + "call_id": "12345", + "version": 0 + }, + "event_id": "$WLGTSEFSEF:localhost", + "origin_server_ts": 1431961217939, + "room_id": "!Cuyf34gef24t:localhost", + "sender": "@example:localhost", + "type": "m.call.hangup" +} +*/ + +using namespace QMatrixClient; + + +CallHangupEvent::CallHangupEvent(const QJsonObject& obj) + : RoomEvent(CallHangup, obj) + , _callId(contentJson()["call_id"].toString()) + , _version(contentJson()["version"].toInt()) +{ + qCDebug(EVENTS) << "Call Hangup event"; +} + +CallHangupEvent::CallHangupEvent(const QString& callId) + : RoomEvent(CallHangup) +{ + _version = 0; + _callId = callId; +} diff --git a/lib/events/callhangupevent.h b/lib/events/callhangupevent.h new file mode 100644 index 00000000..c0f120da --- /dev/null +++ b/lib/events/callhangupevent.h @@ -0,0 +1,52 @@ +/****************************************************************************** + * Copyright (C) 2017 Marius Gripsgard <marius@ubports.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "roomevent.h" + +namespace QMatrixClient +{ + class CallHangupEvent: public RoomEvent + { + public: + DEFINE_EVENT_TYPEID("m.call.hangup", CallHangupEvent) + + explicit CallHangupEvent(const QJsonObject& obj); + + explicit CallHangupEvent(const QString& callId); + + const QString& callId() const { return _callId; } + const int version() const { return _version; } + + QJsonObject toJson() const + { + QJsonObject obj; + obj.insert("call_id", _callId); + obj.insert("version", _version); + return obj; + } + + private: + QString _callId; + int _version; + }; + + REGISTER_EVENT_TYPE(CallHangupEvent) + DEFINE_EVENTTYPE_ALIAS(CallHangup, CallHangupEvent) +} diff --git a/lib/events/callinviteevent.cpp b/lib/events/callinviteevent.cpp new file mode 100644 index 00000000..5eb07ce2 --- /dev/null +++ b/lib/events/callinviteevent.cpp @@ -0,0 +1,68 @@ +/****************************************************************************** + * Copyright (C) 2017 Marius Gripsgard <marius@ubports.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "callinviteevent.h" + +#include "event.h" + +#include "logging.h" + +#include <QtCore/QJsonDocument> + +/* +m.call.invite +{ + "age": 242352, + "content": { + "call_id": "12345", + "lifetime": 60000, + "offer": { + "sdp": "v=0\r\no=- 6584580628695956864 2 IN IP4 127.0.0.1[...]", + "type": "offer" + }, + "version": 0 + }, + "event_id": "$WLGTSEFSEF:localhost", + "origin_server_ts": 1431961217939, + "room_id": "!Cuyf34gef24t:localhost", + "sender": "@example:localhost", + "type": "m.call.invite" +} +*/ + +using namespace QMatrixClient; + +CallInviteEvent::CallInviteEvent(const QJsonObject& obj) + : RoomEvent(CallInvite, obj) + , _lifetime(contentJson()["lifetime"].toInt()) + , _sdp(contentJson()["offer"].toObject()["sdp"].toString()) + , _callId(contentJson()["call_id"].toString()) + , _version(contentJson()["version"].toInt()) +{ + qCDebug(EVENTS) << "Call Invite event"; +} + +CallInviteEvent::CallInviteEvent(const QString& callId, const int lifetime, + const QString& sdp) + : RoomEvent(CallInvite) +{ + _version = 0; + _callId = callId; + _lifetime = lifetime; + _sdp = sdp; +} diff --git a/lib/events/callinviteevent.h b/lib/events/callinviteevent.h new file mode 100644 index 00000000..553a8024 --- /dev/null +++ b/lib/events/callinviteevent.h @@ -0,0 +1,63 @@ +/****************************************************************************** + * Copyright (C) 2017 Marius Gripsgard <marius@ubports.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "roomevent.h" + +namespace QMatrixClient +{ + class CallInviteEvent: public RoomEvent + { + public: + DEFINE_EVENT_TYPEID("m.call.invite", CallInviteEvent) + + explicit CallInviteEvent(const QJsonObject& obj); + + explicit CallInviteEvent(const QString& callId, const int lifetime, + const QString& sdp); + + const int lifetime() const { return _lifetime; } + const QString& sdp() const { return _sdp; } + const QString& callId() const { return _callId; } + const int version() const { return _version; } + + QJsonObject toJson() const + { + QJsonObject offer; + offer.insert("sdp", _sdp); + offer.insert("type", QStringLiteral("offer")); + + QJsonObject obj; + obj.insert("call_id", _callId); + obj.insert("version", _version); + obj.insert("lifetime", _lifetime); + obj.insert("offer", offer); + return obj; + } + + private: + int _lifetime; + QString _sdp; + QString _callId; + int _version; + }; + + REGISTER_EVENT_TYPE(CallInviteEvent) + DEFINE_EVENTTYPE_ALIAS(CallInvite, CallInviteEvent) +} diff --git a/lib/jobs/turnserverjob.cpp b/lib/jobs/turnserverjob.cpp new file mode 100644 index 00000000..fffb7ee9 --- /dev/null +++ b/lib/jobs/turnserverjob.cpp @@ -0,0 +1,58 @@ +/****************************************************************************** + * Copyright (C) 2017 Marius Gripsgard <marius@ubports.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "turnserverjob.h" +#include "util.h" + +using namespace QMatrixClient; + +class TurnServerJob::Private +{ + public: + QJsonObject _turnObject; +}; + +TurnServerJob::TurnServerJob() + : BaseJob(HttpVerb::Get, "TurnServerJob", + QStringLiteral("/_matrix/client/r0/voip/turnServer")) + , d(new Private) +{ +} + +TurnServerJob::~TurnServerJob() +{ + delete d; +} + +QJsonObject TurnServerJob::toJson() const +{ + return d->_turnObject; +} + +BaseJob::Status TurnServerJob::parseJson(const QJsonDocument& data) +{ + QJsonObject json = data.object(); + + if( json.contains("uris") ) + { + d->_turnObject = json; + return Success; + } + + return { UserDefinedError, "turnServer object does not include uris" }; +} diff --git a/lib/jobs/turnserverjob.h b/lib/jobs/turnserverjob.h new file mode 100644 index 00000000..14e28422 --- /dev/null +++ b/lib/jobs/turnserverjob.h @@ -0,0 +1,40 @@ +/****************************************************************************** + * Copyright (C) 2017 Marius Gripsgard <marius@ubports.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "basejob.h" + +namespace QMatrixClient +{ + class TurnServerJob: public BaseJob + { + public: + TurnServerJob(); + virtual ~TurnServerJob(); + + QJsonObject toJson() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + Private* d; + }; +} // namespace QMatrixClient diff --git a/lib/room.cpp b/lib/room.cpp index 07c39498..81e56161 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -33,6 +33,10 @@ #include "events/roommemberevent.h" #include "events/typingevent.h" #include "events/receiptevent.h" +#include "events/callinviteevent.h" +#include "events/callcandidatesevent.h" +#include "events/callanswerevent.h" +#include "events/callhangupevent.h" #include "events/redactionevent.h" #include "jobs/mediathumbnailjob.h" #include "jobs/downloadfilejob.h" @@ -1289,6 +1293,60 @@ 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 true; + } + emit callEvent(room, event); + return false; +} + +bool Room::isCallSupported() const +{ + return d->membersMap.size() == 2; +} + +void Room::inviteCall(const QString& callId, const int lifetime, + const QString& sdp) +{ + Q_ASSERT(isCallSupported()); + CallInviteEvent rme(callId, lifetime, sdp); + connection()->callApi<SendMessageJob>(id(), rme); +} + +void Room::callCandidates(const QString& callId, + const QJsonArray& candidates) +{ + Q_ASSERT(isCallSupported()); + CallCandidatesEvent rme(callId, candidates); + connection()->callApi<SendMessageJob>(id(), rme); +} + +void Room::answerCall(const QString& callId, const int lifetime, + const QString& sdp) +{ + Q_ASSERT(isCallSupported()); + CallAnswerEvent rme(callId, lifetime, sdp); + connection()->callApi<SendMessageJob>(id(), rme); +} + +void Room::answerCall(const QString& callId, const QString& sdp) +{ + Q_ASSERT(isCallSupported()); + CallAnswerEvent rme(callId, sdp); + connection()->callApi<SendMessageJob>(id(), rme); +} + +void Room::hangupCall(const QString& callId) +{ + Q_ASSERT(isCallSupported()); + CallHangupEvent rme(callId); + connection()->callApi<SendMessageJob>(id(), rme); +} + void Room::getPreviousContent(int limit) { d->getPreviousContent(limit); @@ -1764,6 +1822,18 @@ 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() @@ -304,6 +304,18 @@ namespace QMatrixClient QJsonObject toJson() const; void updateData(SyncRoomData&& data ); void setJoinState( JoinState state ); + bool processCall(Room* room, const RoomEvent* event); + + Q_INVOKABLE void inviteCall(const QString& callId, + const int lifetime, const QString& sdp); + Q_INVOKABLE void callCandidates(const QString& callId, + const QJsonArray& candidates); + Q_INVOKABLE void answerCall(const QString& callId, const int lifetime, + const QString& sdp); + Q_INVOKABLE void answerCall(const QString& callId, + const QString& sdp); + Q_INVOKABLE void hangupCall(const QString& callId); + Q_INVOKABLE bool isCallSupported() const; public slots: QString postMessage(const QString& plainText, MessageEventType type); @@ -403,6 +415,8 @@ namespace QMatrixClient void fileTransferFailed(QString id, QString errorMessage = {}); void fileTransferCancelled(QString id); + void callEvent(Room* room, const RoomEvent* event); + protected: /// Returns true if any of room names/aliases has changed virtual bool processStateEvent(const RoomEvent& e); |