Skip to content

Commit

Permalink
Update call events to version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasFella committed May 30, 2023
1 parent 1f71556 commit 50e2784
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 28 deletions.
17 changes: 10 additions & 7 deletions Quotient/events/callevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
using namespace Quotient;

QJsonObject CallEvent::basicJson(const QString& matrixType,
const QString& callId, int version,
const QString& callId, int version, const QString& partyId,
QJsonObject contentJson)
{
contentJson.insert(QStringLiteral("call_id"), callId);
contentJson.insert(QStringLiteral("version"), version);
contentJson.insert(QStringLiteral("party_id"), partyId);
return RoomEvent::basicJson(matrixType, contentJson);
}

Expand All @@ -29,12 +30,13 @@ m.call.invite
"age": 242352,
"content": {
"call_id": "12345",
"party_id": "foo123",
"lifetime": 60000,
"offer": {
"sdp": "v=0\r\no=- 6584580628695956864 2 IN IP4 127.0.0.1[...]",
"type": "offer"
},
"version": 0
"version": "1"
},
"event_id": "$WLGTSEFSEF:localhost",
"origin_server_ts": 1431961217939,
Expand All @@ -44,10 +46,10 @@ m.call.invite
}
*/

CallInviteEvent::CallInviteEvent(const QString& callId, int lifetime,
CallInviteEvent::CallInviteEvent(const QString& callId, const QString& partyId, int lifetime,
const QString& sdp)
: EventTemplate(
callId,
callId, partyId,
{ { QStringLiteral("lifetime"), lifetime },
{ QStringLiteral("offer"),
QJsonObject{ { QStringLiteral("type"), QStringLiteral("offer") },
Expand All @@ -64,7 +66,8 @@ m.call.answer
"type": "answer"
},
"call_id": "12345",
"version": 0
"party_id": "foo123",
"version": "1"
},
"event_id": "$WLGTSEFSEF:localhost",
"origin_server_ts": 1431961217939,
Expand All @@ -74,8 +77,8 @@ m.call.answer
}
*/

CallAnswerEvent::CallAnswerEvent(const QString& callId, const QString& sdp)
: EventTemplate(callId, { { QStringLiteral("answer"),
CallAnswerEvent::CallAnswerEvent(const QString& callId, const QString& partyId, const QString& sdp)
: EventTemplate(callId, partyId, { { QStringLiteral("answer"),
QJsonObject { { QStringLiteral("type"),
QStringLiteral("answer") },
{ QStringLiteral("sdp"), sdp } } } })
Expand Down
49 changes: 42 additions & 7 deletions Quotient/events/callevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ class QUOTIENT_API CallEvent : public RoomEvent {

QUO_CONTENT_GETTER(QString, callId)
QUO_CONTENT_GETTER(int, version)
QUO_CONTENT_GETTER(QString, partyId)

protected:
explicit CallEvent(const QJsonObject& json);

static QJsonObject basicJson(const QString& matrixType,
const QString& callId, int version,
const QString& callId, int version, const QString& partyId,
QJsonObject contentJson = {});
};
using CallEventBase
Expand All @@ -28,9 +29,9 @@ template <typename EventT>
class EventTemplate<EventT, CallEvent> : public CallEvent {
public:
using CallEvent::CallEvent;
explicit EventTemplate(const QString& callId,
explicit EventTemplate(const QString& callId, const QString& partyId,
const QJsonObject& contentJson = {})
: EventTemplate(basicJson(EventT::TypeId, callId, 0, contentJson))
: EventTemplate(basicJson(EventT::TypeId, callId, 1, partyId, contentJson))
{}
};

Expand All @@ -40,10 +41,10 @@ class EventTemplate<EventT, CallEvent, ContentT>
public:
using EventTemplate<EventT, CallEvent>::EventTemplate;
template <typename... ContentParamTs>
explicit EventTemplate(const QString& callId,
explicit EventTemplate(const QString& callId, const QString& partyId,
ContentParamTs&&... contentParams)
: EventTemplate<EventT, CallEvent>(
callId,
callId, partyId,
toJson(ContentT{ std::forward<ContentParamTs>(contentParams)... }))
{}
};
Expand All @@ -55,10 +56,11 @@ class QUOTIENT_API CallInviteEvent

using EventTemplate::EventTemplate;

explicit CallInviteEvent(const QString& callId, int lifetime,
explicit CallInviteEvent(const QString& callId, const QString& partyId, int lifetime,
const QString& sdp);

QUO_CONTENT_GETTER(int, lifetime)
QUO_CONTENT_GETTER(QString, invitee)
QString sdp() const
{
return contentPart<QJsonObject>("offer"_ls).value("sdp"_ls).toString();
Expand All @@ -75,7 +77,7 @@ class QUOTIENT_API CallAnswerEvent

using EventTemplate::EventTemplate;

explicit CallAnswerEvent(const QString& callId, const QString& sdp);
explicit CallAnswerEvent(const QString& callId, const QString& partyId, const QString& sdp);

QString sdp() const
{
Expand All @@ -90,6 +92,39 @@ class QUOTIENT_API CallHangupEvent
using EventTemplate::EventTemplate;
};

class QUOTIENT_API CallNegotiateEvent
: public EventTemplate<CallNegotiateEvent, CallEvent> {
public:
QUO_EVENT(CallNegotiateEvent, "m.call.negotiate")

using EventTemplate::EventTemplate;

explicit CallNegotiateEvent(const QString &callId,
const QString& partyId,
int lifetime,
const QString &sdp);
QUO_CONTENT_GETTER(QString, sdp)
};

class QUOTIENT_API CallRejectEvent
: public EventTemplate<CallRejectEvent, CallEvent> {
public:
QUO_EVENT(CallRejectEvent, "m.call.reject")

using EventTemplate::EventTemplate;
};

class QUOTIENT_API SelectAnswerEvent
: public EventTemplate<SelectAnswerEvent, CallEvent> {
public:
QUO_EVENT(SelectAnswerEvent, "m.call.select_answer")

using EventTemplate::EventTemplate;

explicit SelectAnswerEvent();
QUO_CONTENT_GETTER(QString, selectedPartyId);
};

} // namespace Quotient
Q_DECLARE_METATYPE(Quotient::CallEvent*)
Q_DECLARE_METATYPE(const Quotient::CallEvent*)
19 changes: 10 additions & 9 deletions Quotient/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2370,38 +2370,39 @@ void Room::checkVersion()
}
}

void Room::inviteCall(const QString& callId, const int lifetime,
void Room::inviteCall(const QString& callId, const QString& partyId, const int lifetime,
const QString& sdp)
{
Q_ASSERT(supportsCalls());
d->sendEvent<CallInviteEvent>(callId, lifetime, sdp);
d->sendEvent<CallInviteEvent>(callId, partyId, lifetime, sdp);
}

void Room::sendCallCandidates(const QString& callId,
const QString& partyId,
const QJsonArray& candidates)
{
Q_ASSERT(supportsCalls());
d->sendEvent<CallCandidatesEvent>(callId, candidates);
d->sendEvent<CallCandidatesEvent>(callId, partyId, candidates);
}

void Room::answerCall(const QString& callId, [[maybe_unused]] int lifetime,
void Room::answerCall(const QString& callId, const QString& partyId, [[maybe_unused]] int lifetime,
const QString& sdp)
{
qCWarning(MAIN) << "To client developer: drop lifetime parameter from "
"Room::answerCall(), it is no more accepted";
answerCall(callId, sdp);
answerCall(callId, partyId, sdp);
}

void Room::answerCall(const QString& callId, const QString& sdp)
void Room::answerCall(const QString& callId, const QString& partyId, const QString& sdp)
{
Q_ASSERT(supportsCalls());
d->sendEvent<CallAnswerEvent>(callId, sdp);
d->sendEvent<CallAnswerEvent>(callId, partyId, sdp);
}

void Room::hangupCall(const QString& callId)
void Room::hangupCall(const QString& callId, const QString& partyId)
{
Q_ASSERT(supportsCalls());
d->sendEvent<CallHangupEvent>(callId);
d->sendEvent<CallHangupEvent>(callId, partyId);
}

void Room::getPreviousContent(int limit, const QString& filter)
Expand Down
10 changes: 5 additions & 5 deletions Quotient/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,14 +875,14 @@ public Q_SLOTS:
/// Switch the room's version (aka upgrade)
void switchVersion(QString newVersion);

void inviteCall(const QString& callId, const int lifetime,
void inviteCall(const QString& callId, const QString& partyId, const int lifetime,
const QString& sdp);
void sendCallCandidates(const QString& callId, const QJsonArray& candidates);
void sendCallCandidates(const QString& callId, const QString& partyId, const QJsonArray& candidates);
[[deprecated("Lifetime argument is no more passed; "
"use 2-arg Room::answerCall() instead")]]
void answerCall(const QString& callId, int lifetime, const QString& sdp);
void answerCall(const QString& callId, const QString& sdp);
void hangupCall(const QString& callId);
void answerCall(const QString& callId, const QString& partyId, int lifetime, const QString& sdp);
void answerCall(const QString& callId, const QString& partyId, const QString& sdp);
void hangupCall(const QString& callId, const QString& partyId);

/**
* Activates encryption for this room.
Expand Down

0 comments on commit 50e2784

Please sign in to comment.