libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
callevents.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 Kitsune Ral <Kitsune-Ral@users.sf.net>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include "roomevent.h"
7
8namespace Quotient {
9
10class QUOTIENT_API CallEvent : public RoomEvent {
11public:
12 QUO_BASE_EVENT(CallEvent, RoomEvent, "m.call.*")
13
14 QUO_CONTENT_GETTER(QString, callId)
15 QUO_CONTENT_GETTER(int, version)
16
17protected:
18 explicit CallEvent(const QJsonObject& json);
19
20 static QJsonObject basicJson(const QString& matrixType,
21 const QString& callId, int version,
22 QJsonObject contentJson = {});
23};
24
25template <typename EventT>
26class EventTemplate<EventT, CallEvent> : public CallEvent {
27public:
28 using CallEvent::CallEvent;
29 explicit EventTemplate(const QString& callId,
30 const QJsonObject& contentJson = {})
31 : EventTemplate(basicJson(EventT::TypeId, callId, 0, contentJson))
32 {}
33};
34
35template <typename EventT, typename ContentT>
36class EventTemplate<EventT, CallEvent, ContentT>
37 : public EventTemplate<EventT, CallEvent> {
38public:
39 using EventTemplate<EventT, CallEvent>::EventTemplate;
40 template <typename... ContentParamTs>
41 explicit EventTemplate(const QString& callId,
42 ContentParamTs&&... contentParams)
43 : EventTemplate<EventT, CallEvent>(
44 callId,
45 toJson(ContentT{ std::forward<ContentParamTs>(contentParams)... }))
46 {}
47};
48
49class QUOTIENT_API CallInviteEvent
50 : public EventTemplate<CallInviteEvent, CallEvent> {
51public:
52 QUO_EVENT(CallInviteEvent, "m.call.invite")
53
54 using EventTemplate::EventTemplate;
55
56 explicit CallInviteEvent(const QString& callId, int lifetime,
57 const QString& sdp);
58
59 QUO_CONTENT_GETTER(int, lifetime)
60 QString sdp() const
61 {
62 return contentPart<QJsonObject>("offer"_L1).value("sdp"_L1).toString();
63 }
64};
65
66DEFINE_SIMPLE_EVENT(CallCandidatesEvent, CallEvent, "m.call.candidates",
67 QJsonArray, candidates, "candidates")
68
69class QUOTIENT_API CallAnswerEvent
70 : public EventTemplate<CallAnswerEvent, CallEvent> {
71public:
72 QUO_EVENT(CallAnswerEvent, "m.call.answer")
73
74 using EventTemplate::EventTemplate;
75
76 explicit CallAnswerEvent(const QString& callId, const QString& sdp);
77
78 QString sdp() const
79 {
80 return contentPart<QJsonObject>("answer"_L1).value("sdp"_L1).toString();
81 }
82};
83
84class QUOTIENT_API CallHangupEvent
85 : public EventTemplate<CallHangupEvent, CallEvent> {
86public:
87 QUO_EVENT(CallHangupEvent, "m.call.hangup")
88 using EventTemplate::EventTemplate;
89};
90
91} // namespace Quotient
92Q_DECLARE_METATYPE(Quotient::CallEvent*)
93Q_DECLARE_METATYPE(const Quotient::CallEvent*)
#define QUO_CONTENT_GETTER(PartType_, PartName_)
Define an inline method obtaining a content part.
Definition event.h:465
#define QUO_EVENT(CppType_, MatrixType_)
Supply event metatype information in (specific) event types.
Definition event.h:436
#define DEFINE_SIMPLE_EVENT(Name_, Base_, TypeId_, ValueType_, GetterName_, JsonKey_)
Define a new event class with a single key-value pair in the content.
Definition event.h:476
#define QUO_BASE_EVENT(CppType_, BaseCppType_,...)
Supply event metatype information in base event types.
Definition event.h:408
#define QUOTIENT_API