libQuotient
A Qt library for building matrix clients
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 
8 namespace Quotient {
9 
10 class QUOTIENT_API CallEvent : public RoomEvent {
11 public:
12  QUO_BASE_EVENT(CallEvent, RoomEvent, "m.call.*")
13 
14  QUO_CONTENT_GETTER(QString, callId)
15  QUO_CONTENT_GETTER(int, version)
16 
17 protected:
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 
25 template <typename EventT>
26 class EventTemplate<EventT, CallEvent> : public CallEvent {
27 public:
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 
35 template <typename EventT, typename ContentT>
36 class EventTemplate<EventT, CallEvent, ContentT>
37  : public EventTemplate<EventT, CallEvent> {
38 public:
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 
49 class QUOTIENT_API CallInviteEvent
50  : public EventTemplate<CallInviteEvent, CallEvent> {
51 public:
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 
66 DEFINE_SIMPLE_EVENT(CallCandidatesEvent, CallEvent, "m.call.candidates",
67  QJsonArray, candidates, "candidates")
68 
69 class QUOTIENT_API CallAnswerEvent
70  : public EventTemplate<CallAnswerEvent, CallEvent> {
71 public:
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 
84 class QUOTIENT_API CallHangupEvent
85  : public EventTemplate<CallHangupEvent, CallEvent> {
86 public:
87  QUO_EVENT(CallHangupEvent, "m.call.hangup")
88  using EventTemplate::EventTemplate;
89 };
90 
91 } // namespace Quotient
92 Q_DECLARE_METATYPE(Quotient::CallEvent*)
93 Q_DECLARE_METATYPE(const Quotient::CallEvent*)