1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// SPDX-FileCopyrightText: 2022 Kitsune Ral <Kitsune-Ral@users.sf.net>
// SPDX-License-Identifier: LGPL-2.1-or-later
#pragma once
#include "roomevent.h"
namespace Quotient {
class QUOTIENT_API CallEvent : public RoomEvent {
public:
QUO_BASE_EVENT(CallEvent, "m.call.*"_ls, RoomEvent::BaseMetaType)
static bool matches(const QJsonObject&, const QString& mType)
{
return mType.startsWith("m.call.");
}
explicit CallEvent(const QJsonObject& json);
QUO_CONTENT_GETTER(QString, callId)
QUO_CONTENT_GETTER(int, version)
protected:
static QJsonObject basicJson(const QString& matrixType,
const QString& callId, int version,
QJsonObject contentJson = {});
};
using CallEventBase
[[deprecated("CallEventBase is CallEvent now")]] = CallEvent;
template <typename EventT>
class EventTemplate<EventT, CallEvent> : public CallEvent {
public:
using CallEvent::CallEvent;
explicit EventTemplate(const QString& callId,
const QJsonObject& contentJson = {})
: EventTemplate(basicJson(EventT::TypeId, callId, 0, contentJson))
{}
};
template <typename EventT, typename ContentT>
class EventTemplate<EventT, CallEvent, ContentT>
: public EventTemplate<EventT, CallEvent> {
public:
using EventTemplate<EventT, CallEvent>::EventTemplate;
template <typename... ContentParamTs>
explicit EventTemplate(const QString& callId,
ContentParamTs&&... contentParams)
: EventTemplate<EventT, CallEvent>(
callId,
toJson(ContentT{ std::forward<ContentParamTs>(contentParams)... }))
{}
};
class QUOTIENT_API CallInviteEvent
: public EventTemplate<CallInviteEvent, CallEvent> {
public:
QUO_EVENT(CallInviteEvent, "m.call.invite")
using EventTemplate::EventTemplate;
explicit CallInviteEvent(const QString& callId, int lifetime,
const QString& sdp);
QUO_CONTENT_GETTER(int, lifetime)
QString sdp() const
{
return contentPart<QJsonObject>("offer"_ls).value("sdp"_ls).toString();
}
};
DEFINE_SIMPLE_EVENT(CallCandidatesEvent, CallEvent, "m.call.candidates",
QJsonArray, candidates, "candidates")
class QUOTIENT_API CallAnswerEvent
: public EventTemplate<CallAnswerEvent, CallEvent> {
public:
QUO_EVENT(CallAnswerEvent, "m.call.answer")
using EventTemplate::EventTemplate;
explicit CallAnswerEvent(const QString& callId, const QString& sdp);
QString sdp() const
{
return contentPart<QJsonObject>("answer"_ls).value("sdp"_ls).toString();
}
};
class QUOTIENT_API CallHangupEvent
: public EventTemplate<CallHangupEvent, CallEvent> {
public:
QUO_EVENT(CallHangupEvent, "m.call.hangup")
using EventTemplate::EventTemplate;
};
} // namespace Quotient
Q_DECLARE_METATYPE(Quotient::CallEvent*)
Q_DECLARE_METATYPE(const Quotient::CallEvent*)
|