1 | #pragma once |
2 | |
3 | /// @file |
4 | /// @brief Call related events. |
5 | |
6 | #if __has_include(<nlohmann/json_fwd.hpp>) |
7 | #include <nlohmann/json_fwd.hpp> |
8 | #else |
9 | #include <nlohmann/json.hpp> |
10 | #endif |
11 | |
12 | #include <string> |
13 | #include <vector> |
14 | |
15 | namespace mtx { |
16 | namespace events { |
17 | namespace voip { |
18 | |
19 | //! Universal RTC Session Description structure compatible with the WebRTC API |
20 | struct RTCSessionDescriptionInit |
21 | { |
22 | enum class Type |
23 | { |
24 | Answer, |
25 | Offer, |
26 | |
27 | }; |
28 | //! The SDP text of the session description. |
29 | std::string sdp; |
30 | //! The type of session description. |
31 | Type type; |
32 | |
33 | friend void from_json(const nlohmann::json &obj, RTCSessionDescriptionInit &content); |
34 | friend void to_json(nlohmann::json &obj, const RTCSessionDescriptionInit &content); |
35 | }; |
36 | |
37 | //! Content for the `m.call.invite` event. |
38 | struct CallInvite |
39 | { |
40 | //! A unique identifier for the call. |
41 | std::string call_id; |
42 | //! A unique identifier for the client participating in the event. |
43 | std::string party_id; |
44 | //! The session description object |
45 | RTCSessionDescriptionInit offer; |
46 | //! The version of the VoIP specification this message adheres to. |
47 | std::string version; |
48 | //! The time in milliseconds that the invite is valid for. Recommended 90000ms |
49 | uint32_t lifetime = 90000; |
50 | //! The ID of the user that the call is being placed to. See MSC2746. |
51 | std::string invitee; |
52 | |
53 | friend void from_json(const nlohmann::json &obj, CallInvite &content); |
54 | friend void to_json(nlohmann::json &obj, const CallInvite &content); |
55 | }; |
56 | |
57 | //! Content for the `m.call.candidates` event |
58 | struct CallCandidates |
59 | { |
60 | struct Candidate |
61 | { |
62 | //! The SDP media type this candidate is intended for. |
63 | std::string sdpMid; |
64 | //! The index of the SDP 'm' line this candidate is intended for. |
65 | uint16_t sdpMLineIndex; |
66 | //! The SDP 'a' line of the candidate. |
67 | std::string candidate; |
68 | }; |
69 | |
70 | //! The ID of the call this event relates to. |
71 | std::string call_id; |
72 | //! A unique identifier for the client participating in the event. |
73 | std::string party_id; |
74 | //! Array of objects describing the candidates. |
75 | std::vector<Candidate> candidates; |
76 | //! The version of the VoIP specification this message adheres to. |
77 | std::string version; |
78 | |
79 | friend void from_json(const nlohmann::json &obj, CallCandidates &content); |
80 | friend void to_json(nlohmann::json &obj, const CallCandidates &content); |
81 | }; |
82 | |
83 | //! Content for the `m.call.answer` event |
84 | struct CallAnswer |
85 | { |
86 | //! The ID of the call this event relates to. |
87 | std::string call_id; |
88 | //! A unique identifier for the client participating in the event. |
89 | std::string party_id; |
90 | //! The version of the VoIP specification this message adheres to. |
91 | std::string version; |
92 | //! The session description object |
93 | RTCSessionDescriptionInit answer; |
94 | |
95 | friend void from_json(const nlohmann::json &obj, CallAnswer &content); |
96 | friend void to_json(nlohmann::json &obj, const CallAnswer &content); |
97 | }; |
98 | |
99 | //! Content for the `m.call.hangup` event |
100 | struct CallHangUp |
101 | { |
102 | enum class Reason |
103 | { |
104 | ICEFailed, |
105 | InviteTimeOut, |
106 | ICETimeOut, |
107 | UserHangUp, |
108 | UserMediaFailed, |
109 | UserBusy, |
110 | UnknownError, |
111 | User |
112 | }; |
113 | |
114 | //! The ID of the call this event relates to. |
115 | std::string call_id; |
116 | //! A unique identifier for the client participating in the event. |
117 | std::string party_id; |
118 | //! The version of the VoIP specification this message adheres to. |
119 | std::string version; |
120 | //! The reason for the call hang up. |
121 | Reason reason = Reason::UserHangUp; |
122 | |
123 | friend void from_json(const nlohmann::json &obj, CallHangUp &content); |
124 | friend void to_json(nlohmann::json &obj, const CallHangUp &content); |
125 | }; |
126 | |
127 | //! Content for the `m.call.select_answer` event. See MSC2746. |
128 | struct CallSelectAnswer |
129 | { |
130 | //! The ID of the call this event relates to. |
131 | std::string call_id; |
132 | //! A unique identifier for the client participating in the event. |
133 | std::string party_id; |
134 | //! The version of the VoIP specification this message adheres to. |
135 | std::string version; |
136 | //! The ID of the selected party. |
137 | std::string selected_party_id; |
138 | |
139 | friend void from_json(const nlohmann::json &obj, CallSelectAnswer &content); |
140 | friend void to_json(nlohmann::json &obj, const CallSelectAnswer &content); |
141 | }; |
142 | |
143 | //! Content for the `m.call.reject` event. See MSC2746. |
144 | struct CallReject |
145 | { |
146 | //! The ID of the call this event relates to. |
147 | std::string call_id; |
148 | //! A unique identifier for the client participating in the event. |
149 | std::string party_id; |
150 | //! The version of the VoIP specification this message adheres to. |
151 | std::string version; |
152 | |
153 | friend void from_json(const nlohmann::json &obj, CallReject &content); |
154 | friend void to_json(nlohmann::json &obj, const CallReject &content); |
155 | }; |
156 | |
157 | //! Content for the `m.call.negotiate` event. See MSC2746. |
158 | struct CallNegotiate |
159 | { |
160 | //! The ID of the call this event relates to. |
161 | std::string call_id; |
162 | //! A unique identifier for the client participating in the event. |
163 | std::string party_id; |
164 | //! The time in milliseconds that the negotiation is valid for. Recommended 90000ms. |
165 | uint32_t lifetime = 90000; |
166 | //! The session description object |
167 | RTCSessionDescriptionInit description; |
168 | |
169 | friend void from_json(const nlohmann::json &obj, CallNegotiate &content); |
170 | friend void to_json(nlohmann::json &obj, const CallNegotiate &content); |
171 | }; |
172 | |
173 | } // namespace mtx::events::voip |
174 | } |
175 | } |
176 | |