From 41b408334619a6e755fffbef1c40e7165ab0e0f7 Mon Sep 17 00:00:00 2001 From: Josip Delic Date: Sat, 25 Aug 2018 13:33:24 +0200 Subject: Update marius voip to new libqtmc --- CMakeLists.txt | 5 +++ lib/connection.cpp | 10 +++++ lib/connection.h | 2 + lib/events/callanswerevent.cpp | 76 ++++++++++++++++++++++++++++++++++++++ lib/events/callanswerevent.h | 66 +++++++++++++++++++++++++++++++++ lib/events/callcandidatesevent.cpp | 69 ++++++++++++++++++++++++++++++++++ lib/events/callcandidatesevent.h | 56 ++++++++++++++++++++++++++++ lib/events/callhangupevent.cpp | 59 +++++++++++++++++++++++++++++ lib/events/callhangupevent.h | 52 ++++++++++++++++++++++++++ lib/events/callinviteevent.cpp | 68 ++++++++++++++++++++++++++++++++++ lib/events/callinviteevent.h | 63 +++++++++++++++++++++++++++++++ lib/jobs/turnserverjob.cpp | 58 +++++++++++++++++++++++++++++ lib/jobs/turnserverjob.h | 40 ++++++++++++++++++++ lib/room.cpp | 70 +++++++++++++++++++++++++++++++++++ lib/room.h | 14 +++++++ libqmatrixclient.pri | 10 +++++ 16 files changed, 718 insertions(+) create mode 100644 lib/events/callanswerevent.cpp create mode 100644 lib/events/callanswerevent.h create mode 100644 lib/events/callcandidatesevent.cpp create mode 100644 lib/events/callcandidatesevent.h create mode 100644 lib/events/callhangupevent.cpp create mode 100644 lib/events/callhangupevent.h create mode 100644 lib/events/callinviteevent.cpp create mode 100644 lib/events/callinviteevent.h create mode 100644 lib/jobs/turnserverjob.cpp create mode 100644 lib/jobs/turnserverjob.h diff --git a/CMakeLists.txt b/CMakeLists.txt index fa48db03..e9b847f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,12 +89,17 @@ set(libqmatrixclient_SRCS lib/events/roommemberevent.cpp lib/events/typingevent.cpp lib/events/receiptevent.cpp + lib/events/callanswerevent.cpp + lib/events/callcandidatesevent.cpp + lib/events/callhangupevent.cpp + lib/events/callinviteevent.cpp lib/events/directchatevent.cpp lib/jobs/requestdata.cpp lib/jobs/basejob.cpp lib/jobs/syncjob.cpp lib/jobs/mediathumbnailjob.cpp lib/jobs/downloadfilejob.cpp + lib/jobs/turnserverjob.cpp ) set(CSAPI_DIR csapi) 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 #include @@ -1189,3 +1190,12 @@ void Connection::setCacheState(bool newValue) emit cacheStateChanged(); } } + +void Connection::getTurnServers() +{ + auto job = callApi(); + 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 + * + * 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 + +/* +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 + * + * 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 + * + * 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 + +/* +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 + * + * 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 + * + * 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 + +/* +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 + * + * 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 + * + * 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 + +/* +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 + * + * 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 + * + * 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 + * + * 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(id(), rme); +} + +void Room::callCandidates(const QString& callId, + const QJsonArray& candidates) +{ + Q_ASSERT(isCallSupported()); + CallCandidatesEvent rme(callId, candidates); + connection()->callApi(id(), rme); +} + +void Room::answerCall(const QString& callId, const int lifetime, + const QString& sdp) +{ + Q_ASSERT(isCallSupported()); + CallAnswerEvent rme(callId, lifetime, sdp); + connection()->callApi(id(), rme); +} + +void Room::answerCall(const QString& callId, const QString& sdp) +{ + Q_ASSERT(isCallSupported()); + CallAnswerEvent rme(callId, sdp); + connection()->callApi(id(), rme); +} + +void Room::hangupCall(const QString& callId) +{ + Q_ASSERT(isCallSupported()); + CallHangupEvent rme(callId); + connection()->callApi(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() diff --git a/lib/room.h b/lib/room.h index 75cd7354..fa5762e2 100644 --- a/lib/room.h +++ b/lib/room.h @@ -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); diff --git a/libqmatrixclient.pri b/libqmatrixclient.pri index f931be32..555ef073 100644 --- a/libqmatrixclient.pri +++ b/libqmatrixclient.pri @@ -28,6 +28,10 @@ HEADERS += \ $$SRCPATH/events/roomavatarevent.h \ $$SRCPATH/events/typingevent.h \ $$SRCPATH/events/receiptevent.h \ + $$SRCPATH/events/callanswerevent.h \ + $$SRCPATH/events/callcandidatesevent.h \ + $$SRCPATH/events/callhangupevent.h \ + $$SRCPATH/events/callinviteevent.h \ $$SRCPATH/events/accountdataevents.h \ $$SRCPATH/events/directchatevent.h \ $$SRCPATH/events/redactionevent.h \ @@ -36,6 +40,7 @@ HEADERS += \ $$SRCPATH/jobs/basejob.h \ $$SRCPATH/jobs/syncjob.h \ $$SRCPATH/jobs/mediathumbnailjob.h \ + $$SRCPATH/jobs/turnserverjob.h \ $$SRCPATH/jobs/downloadfilejob.h \ $$SRCPATH/jobs/postreadmarkersjob.h \ $$files($$SRCPATH/csapi/*.h, false) \ @@ -62,12 +67,17 @@ SOURCES += \ $$SRCPATH/events/roommessageevent.cpp \ $$SRCPATH/events/roommemberevent.cpp \ $$SRCPATH/events/typingevent.cpp \ + $$SRCPATH/events/callanswerevent.cpp \ + $$SRCPATH/events/callcandidatesevent.cpp \ + $$SRCPATH/events/callhangupevent.cpp \ + $$SRCPATH/events/callinviteevent.cpp \ $$SRCPATH/events/receiptevent.cpp \ $$SRCPATH/events/directchatevent.cpp \ $$SRCPATH/jobs/requestdata.cpp \ $$SRCPATH/jobs/basejob.cpp \ $$SRCPATH/jobs/syncjob.cpp \ $$SRCPATH/jobs/mediathumbnailjob.cpp \ + $$SRCPATH/jobs/turnserverjob.cpp \ $$SRCPATH/jobs/downloadfilejob.cpp \ $$files($$SRCPATH/csapi/*.cpp, false) \ $$files($$SRCPATH/csapi/definitions/*.cpp, false) \ -- cgit v1.2.3 From 508d1f5e14f0286bb3feaf74c4f143ce2a950234 Mon Sep 17 00:00:00 2001 From: Josip Delic Date: Sat, 25 Aug 2018 20:17:29 +0200 Subject: Update make it compile --- lib/events/callanswerevent.cpp | 6 +++--- lib/events/callanswerevent.h | 2 +- lib/events/callcandidatesevent.cpp | 4 ++-- lib/events/callcandidatesevent.h | 1 + lib/events/callhangupevent.cpp | 4 ++-- lib/events/callinviteevent.cpp | 4 ++-- lib/jobs/turnserverjob.h | 1 + lib/room.cpp | 20 ++++++++++---------- 8 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/events/callanswerevent.cpp b/lib/events/callanswerevent.cpp index 14221bc1..c28ad305 100644 --- a/lib/events/callanswerevent.cpp +++ b/lib/events/callanswerevent.cpp @@ -48,7 +48,7 @@ m.call.answer using namespace QMatrixClient; CallAnswerEvent::CallAnswerEvent(const QJsonObject& obj) - : RoomEvent(CallAnswer, obj) + : RoomEvent(typeId(), obj) , _lifetime(contentJson()["lifetime"].toInt()) , _sdp(contentJson()["answer"].toObject()["sdp"].toString()) , _callId(contentJson()["call_id"].toString()) @@ -59,7 +59,7 @@ CallAnswerEvent::CallAnswerEvent(const QJsonObject& obj) CallAnswerEvent::CallAnswerEvent(const QString& callId, const int lifetime, const QString& sdp) - : RoomEvent(CallAnswer) + : RoomEvent(typeId(), NULL) { _version = 0; _callId = callId; @@ -68,7 +68,7 @@ CallAnswerEvent::CallAnswerEvent(const QString& callId, const int lifetime, } CallAnswerEvent::CallAnswerEvent(const QString& callId, const QString& sdp) - : RoomEvent(CallAnswer) + : RoomEvent(typeId(), NULL) { _version = 0; _callId = callId; diff --git a/lib/events/callanswerevent.h b/lib/events/callanswerevent.h index b26a66c3..05a20aac 100644 --- a/lib/events/callanswerevent.h +++ b/lib/events/callanswerevent.h @@ -63,4 +63,4 @@ namespace QMatrixClient REGISTER_EVENT_TYPE(CallAnswerEvent) DEFINE_EVENTTYPE_ALIAS(CallAnswer, CallAnswerEvent) -} +} // namespace QMatrixClient diff --git a/lib/events/callcandidatesevent.cpp b/lib/events/callcandidatesevent.cpp index bf7f0f79..40d9ce05 100644 --- a/lib/events/callcandidatesevent.cpp +++ b/lib/events/callcandidatesevent.cpp @@ -51,7 +51,7 @@ using namespace QMatrixClient; CallCandidatesEvent::CallCandidatesEvent(const QJsonObject& obj) - : RoomEvent(CallCandidates, obj) + : RoomEvent(typeId(), obj) , _candidates(contentJson()["candidates"].toArray()) , _callId(contentJson()["call_id"].toString()) , _version(contentJson()["version"].toInt()) @@ -61,7 +61,7 @@ CallCandidatesEvent::CallCandidatesEvent(const QJsonObject& obj) CallCandidatesEvent::CallCandidatesEvent(const QString& callId, const QJsonArray& candidates) - : RoomEvent(CallCandidates) + : RoomEvent(typeId(), NULL) { _version = 0; _callId = callId; diff --git a/lib/events/callcandidatesevent.h b/lib/events/callcandidatesevent.h index fa2de993..faf3fb7d 100644 --- a/lib/events/callcandidatesevent.h +++ b/lib/events/callcandidatesevent.h @@ -19,6 +19,7 @@ #pragma once #include "roomevent.h" +#include namespace QMatrixClient { diff --git a/lib/events/callhangupevent.cpp b/lib/events/callhangupevent.cpp index e83f506f..27f41a5f 100644 --- a/lib/events/callhangupevent.cpp +++ b/lib/events/callhangupevent.cpp @@ -44,7 +44,7 @@ using namespace QMatrixClient; CallHangupEvent::CallHangupEvent(const QJsonObject& obj) - : RoomEvent(CallHangup, obj) + : RoomEvent(typeId(), obj) , _callId(contentJson()["call_id"].toString()) , _version(contentJson()["version"].toInt()) { @@ -52,7 +52,7 @@ CallHangupEvent::CallHangupEvent(const QJsonObject& obj) } CallHangupEvent::CallHangupEvent(const QString& callId) - : RoomEvent(CallHangup) + : RoomEvent(typeId(), NULL) { _version = 0; _callId = callId; diff --git a/lib/events/callinviteevent.cpp b/lib/events/callinviteevent.cpp index 5eb07ce2..71c49d66 100644 --- a/lib/events/callinviteevent.cpp +++ b/lib/events/callinviteevent.cpp @@ -48,7 +48,7 @@ m.call.invite using namespace QMatrixClient; CallInviteEvent::CallInviteEvent(const QJsonObject& obj) - : RoomEvent(CallInvite, obj) + : RoomEvent(typeId(), obj) , _lifetime(contentJson()["lifetime"].toInt()) , _sdp(contentJson()["offer"].toObject()["sdp"].toString()) , _callId(contentJson()["call_id"].toString()) @@ -59,7 +59,7 @@ CallInviteEvent::CallInviteEvent(const QJsonObject& obj) CallInviteEvent::CallInviteEvent(const QString& callId, const int lifetime, const QString& sdp) - : RoomEvent(CallInvite) + : RoomEvent(typeId(), NULL) { _version = 0; _callId = callId; diff --git a/lib/jobs/turnserverjob.h b/lib/jobs/turnserverjob.h index 14e28422..adbef3ba 100644 --- a/lib/jobs/turnserverjob.h +++ b/lib/jobs/turnserverjob.h @@ -19,6 +19,7 @@ #pragma once #include "basejob.h" +#include namespace QMatrixClient { diff --git a/lib/room.cpp b/lib/room.cpp index 81e56161..ea1386ad 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1313,38 +1313,38 @@ void Room::inviteCall(const QString& callId, const int lifetime, const QString& sdp) { Q_ASSERT(isCallSupported()); - CallInviteEvent rme(callId, lifetime, sdp); - connection()->callApi(id(), rme); + auto *evt = new CallInviteEvent(callId, lifetime, sdp); + postEvent(evt); } void Room::callCandidates(const QString& callId, const QJsonArray& candidates) { Q_ASSERT(isCallSupported()); - CallCandidatesEvent rme(callId, candidates); - connection()->callApi(id(), rme); + auto *evt = new CallCandidatesEvent(callId, candidates); + postEvent(evt); } void Room::answerCall(const QString& callId, const int lifetime, const QString& sdp) { Q_ASSERT(isCallSupported()); - CallAnswerEvent rme(callId, lifetime, sdp); - connection()->callApi(id(), rme); + auto *evt = new CallAnswerEvent(callId, lifetime, sdp); + postEvent(evt); } void Room::answerCall(const QString& callId, const QString& sdp) { Q_ASSERT(isCallSupported()); - CallAnswerEvent rme(callId, sdp); - connection()->callApi(id(), rme); + auto *evt = new CallAnswerEvent(callId, sdp); + postEvent(evt); } void Room::hangupCall(const QString& callId) { Q_ASSERT(isCallSupported()); - CallHangupEvent rme(callId); - connection()->callApi(id(), rme); + auto *evt = new CallHangupEvent(callId); + postEvent(evt); } void Room::getPreviousContent(int limit) -- cgit v1.2.3 From 9357d2bb37029858b397d17e8aa64e57da4202e8 Mon Sep 17 00:00:00 2001 From: Josip Delic Date: Sat, 25 Aug 2018 21:32:32 +0200 Subject: Set state event --- lib/events/callanswerevent.h | 2 ++ lib/events/callcandidatesevent.h | 2 ++ lib/events/callhangupevent.h | 2 ++ lib/events/callinviteevent.h | 2 ++ 4 files changed, 8 insertions(+) diff --git a/lib/events/callanswerevent.h b/lib/events/callanswerevent.h index 05a20aac..b5b47899 100644 --- a/lib/events/callanswerevent.h +++ b/lib/events/callanswerevent.h @@ -33,6 +33,8 @@ namespace QMatrixClient const QString& sdp); explicit CallAnswerEvent(const QString& callId, const QString& sdp); + bool isStateEvent() const override { return true; } + const int lifetime() const { return _lifetime; } const QString& sdp() const { return _sdp; } const QString& callId() const { return _callId; } diff --git a/lib/events/callcandidatesevent.h b/lib/events/callcandidatesevent.h index faf3fb7d..8e66499d 100644 --- a/lib/events/callcandidatesevent.h +++ b/lib/events/callcandidatesevent.h @@ -33,6 +33,8 @@ namespace QMatrixClient explicit CallCandidatesEvent(const QString& callId, const QJsonArray& candidates); + bool isStateEvent() const override { return true; } + const QJsonArray& candidates() const { return _candidates; } const QString& callId() const { return _callId; } const int version() const { return _version; } diff --git a/lib/events/callhangupevent.h b/lib/events/callhangupevent.h index c0f120da..57e565a6 100644 --- a/lib/events/callhangupevent.h +++ b/lib/events/callhangupevent.h @@ -31,6 +31,8 @@ namespace QMatrixClient explicit CallHangupEvent(const QString& callId); + bool isStateEvent() const override { return true; } + const QString& callId() const { return _callId; } const int version() const { return _version; } diff --git a/lib/events/callinviteevent.h b/lib/events/callinviteevent.h index 553a8024..029b2e3d 100644 --- a/lib/events/callinviteevent.h +++ b/lib/events/callinviteevent.h @@ -32,6 +32,8 @@ namespace QMatrixClient explicit CallInviteEvent(const QString& callId, const int lifetime, const QString& sdp); + bool isStateEvent() const override { return true; } + const int lifetime() const { return _lifetime; } const QString& sdp() const { return _sdp; } const QString& callId() const { return _callId; } -- cgit v1.2.3 From 8d07a6bec2689a81c3c3db64e5457143bd671223 Mon Sep 17 00:00:00 2001 From: Josip Delic Date: Wed, 29 Aug 2018 21:51:22 +0200 Subject: Use GetTurnServerJob for csapi --- lib/connection.cpp | 8 +++---- lib/jobs/turnserverjob.cpp | 58 ---------------------------------------------- lib/jobs/turnserverjob.h | 41 -------------------------------- 3 files changed, 4 insertions(+), 103 deletions(-) delete mode 100644 lib/jobs/turnserverjob.cpp delete mode 100644 lib/jobs/turnserverjob.h diff --git a/lib/connection.cpp b/lib/connection.cpp index 853b2a8a..05dec7f9 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -34,7 +34,7 @@ #include "jobs/syncjob.h" #include "jobs/mediathumbnailjob.h" #include "jobs/downloadfilejob.h" -#include "jobs/turnserverjob.h" +#include "csapi/voip.h" #include #include @@ -1193,9 +1193,9 @@ void Connection::setCacheState(bool newValue) void Connection::getTurnServers() { - auto job = callApi(); - connect( job, &TurnServerJob::success, [=] { - emit turnServersChanged(job->toJson()); + auto job = callApi(); + connect( job, &GetTurnServerJob::success, [=] { + emit turnServersChanged(job->data()); }); } diff --git a/lib/jobs/turnserverjob.cpp b/lib/jobs/turnserverjob.cpp deleted file mode 100644 index fffb7ee9..00000000 --- a/lib/jobs/turnserverjob.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2017 Marius Gripsgard - * - * 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 deleted file mode 100644 index adbef3ba..00000000 --- a/lib/jobs/turnserverjob.h +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2017 Marius Gripsgard - * - * 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" -#include - -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 -- cgit v1.2.3 From e7ccd1dd76b9a5124b7c9cf06cbcab029050d8df Mon Sep 17 00:00:00 2001 From: Josip Delic Date: Mon, 17 Sep 2018 11:31:06 +0200 Subject: remove tunrnserver --- libqmatrixclient.pri | 2 -- 1 file changed, 2 deletions(-) diff --git a/libqmatrixclient.pri b/libqmatrixclient.pri index 555ef073..2bb3b499 100644 --- a/libqmatrixclient.pri +++ b/libqmatrixclient.pri @@ -40,7 +40,6 @@ HEADERS += \ $$SRCPATH/jobs/basejob.h \ $$SRCPATH/jobs/syncjob.h \ $$SRCPATH/jobs/mediathumbnailjob.h \ - $$SRCPATH/jobs/turnserverjob.h \ $$SRCPATH/jobs/downloadfilejob.h \ $$SRCPATH/jobs/postreadmarkersjob.h \ $$files($$SRCPATH/csapi/*.h, false) \ @@ -77,7 +76,6 @@ SOURCES += \ $$SRCPATH/jobs/basejob.cpp \ $$SRCPATH/jobs/syncjob.cpp \ $$SRCPATH/jobs/mediathumbnailjob.cpp \ - $$SRCPATH/jobs/turnserverjob.cpp \ $$SRCPATH/jobs/downloadfilejob.cpp \ $$files($$SRCPATH/csapi/*.cpp, false) \ $$files($$SRCPATH/csapi/definitions/*.cpp, false) \ -- cgit v1.2.3 From 8837f87bd94f4daa20a7645a1c4ba0dafe842001 Mon Sep 17 00:00:00 2001 From: Josip Delic Date: Mon, 17 Sep 2018 11:33:10 +0200 Subject: remove tunrnserver --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d08b13f0..48c99715 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,6 @@ set(libqmatrixclient_SRCS lib/jobs/syncjob.cpp lib/jobs/mediathumbnailjob.cpp lib/jobs/downloadfilejob.cpp - lib/jobs/turnserverjob.cpp ) set(CSAPI_DIR csapi) -- cgit v1.2.3 From c1a3dd719b735f7f77306d92baf5923df4fb0b10 Mon Sep 17 00:00:00 2001 From: Josip Delic Date: Mon, 17 Sep 2018 11:45:45 +0200 Subject: return false in processStateEvent; make processCall private --- lib/room.cpp | 2 +- lib/room.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/room.cpp b/lib/room.cpp index 2b81d47d..b7e8195d 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1296,7 +1296,7 @@ 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; + return false; } emit callEvent(room, event); return false; diff --git a/lib/room.h b/lib/room.h index 403207dd..c71d10e0 100644 --- a/lib/room.h +++ b/lib/room.h @@ -302,8 +302,6 @@ namespace QMatrixClient MemberSorter memberSorter() const; - 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, @@ -438,6 +436,8 @@ namespace QMatrixClient const RoomEvent& /*after*/) { } private: + bool processCall(Room* room, const RoomEvent* event); + class Private; Private* d; }; -- cgit v1.2.3