Line data Source code
1 : /*
2 : * Famedly Matrix SDK
3 : * Copyright (C) 2021 Famedly GmbH
4 : *
5 : * This program is free software: you can redistribute it and/or modify
6 : * it under the terms of the GNU Affero General Public License as
7 : * published by the Free Software Foundation, either version 3 of the
8 : * License, or (at your option) any later version.
9 : *
10 : * This program is distributed in the hope that it will be useful,
11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : * GNU Affero General Public License for more details.
14 : *
15 : * You should have received a copy of the GNU Affero General Public License
16 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 : */
18 :
19 : class CallReplacesTarget {
20 : String? id;
21 : String? display_name;
22 : String? avatar_url;
23 :
24 0 : CallReplacesTarget({this.id, this.display_name, this.avatar_url});
25 0 : factory CallReplacesTarget.fromJson(Map<String, dynamic> json) =>
26 0 : CallReplacesTarget(
27 0 : id: json['id'].toString(),
28 0 : display_name: json['display_name'].toString(),
29 0 : avatar_url: json['avatar_url'].toString(),
30 : );
31 :
32 0 : Map<String, dynamic> toJson() => {
33 0 : if (id != null) 'id': id,
34 0 : if (display_name != null) 'display_name': display_name,
35 0 : if (avatar_url != null) 'avatar_url': avatar_url,
36 : };
37 : }
38 :
39 : /// MSC2747: VoIP call transfers
40 : /// https://github.com/matrix-org/matrix-doc/pull/2747
41 : class CallReplaces {
42 : String? replacement_id;
43 : CallReplacesTarget? target_user;
44 : String? create_call;
45 : String? await_call;
46 : String? target_room;
47 :
48 2 : CallReplaces({
49 : this.replacement_id,
50 : this.target_user,
51 : this.create_call,
52 : this.await_call,
53 : this.target_room,
54 : });
55 0 : factory CallReplaces.fromJson(Map<String, dynamic> json) => CallReplaces(
56 0 : replacement_id: json['replacement_id']?.toString(),
57 0 : create_call: json['create_call']?.toString(),
58 0 : await_call: json['await_call']?.toString(),
59 0 : target_room: json['target_room']?.toString(),
60 0 : target_user: CallReplacesTarget.fromJson(json['target_user']),
61 : );
62 :
63 4 : Map<String, Object> toJson() => {
64 2 : if (replacement_id != null) 'replacement_id': replacement_id!,
65 2 : if (target_user != null) 'target_user': target_user!.toJson(),
66 2 : if (create_call != null) 'create_call': create_call!,
67 2 : if (await_call != null) 'await_call': await_call!,
68 2 : if (target_room != null) 'target_room': target_room!,
69 : };
70 : }
71 :
72 : // TODO: Change to "sdp_stream_metadata" when MSC3077 is merged
73 : const String sdpStreamMetadataKey = 'org.matrix.msc3077.sdp_stream_metadata';
74 :
75 : /// https://github.com/matrix-org/matrix-doc/blob/dbkr/msc2747/proposals/2747-voip-call-transfer.md#capability-advertisment
76 : /// https://github.com/matrix-org/matrix-doc/blob/dbkr/msc2746/proposals/2746-reliable-voip.md#add-dtmf
77 : class CallCapabilities {
78 : bool transferee;
79 : bool dtmf;
80 2 : CallCapabilities({this.transferee = false, this.dtmf = false});
81 0 : factory CallCapabilities.fromJson(Map<String, dynamic> json) =>
82 0 : CallCapabilities(
83 0 : dtmf: json['m.call.dtmf'] as bool? ?? false,
84 0 : transferee: json['m.call.transferee'] as bool? ?? false,
85 : );
86 4 : Map<String, dynamic> toJson() => {
87 2 : 'm.call.transferee': transferee,
88 2 : 'm.call.dtmf': dtmf,
89 : };
90 : }
91 :
92 : /// MSC3077: Support for multi-stream VoIP
93 : /// https://github.com/matrix-org/matrix-doc/pull/3077
94 : ///
95 : /// MSC3291: Muting in VoIP calls
96 : /// https://github.com/SimonBrandner/matrix-doc/blob/msc/muting/proposals/3291-muting.md
97 : ///
98 : /// This MSC proposes adding an sdp_stream_metadata field
99 : /// to the events containing a session description i.e.:
100 : /// m.call.invite, m.call.answer, m.call.negotiate
101 : ///
102 : class SDPStreamPurpose {
103 : // SDPStreamMetadataPurpose
104 : String purpose;
105 : bool audio_muted;
106 : bool video_muted;
107 :
108 2 : SDPStreamPurpose({
109 : required this.purpose,
110 : this.audio_muted = false,
111 : this.video_muted = false,
112 : });
113 0 : factory SDPStreamPurpose.fromJson(Map<String, dynamic> json) =>
114 0 : SDPStreamPurpose(
115 0 : audio_muted: json['audio_muted'] as bool? ?? false,
116 0 : video_muted: json['video_muted'] as bool? ?? false,
117 0 : purpose: json['purpose'] as String,
118 : );
119 :
120 4 : Map<String, dynamic> toJson() => {
121 2 : 'purpose': purpose,
122 2 : 'audio_muted': audio_muted,
123 2 : 'video_muted': video_muted,
124 : };
125 : }
126 :
127 : class SDPStreamMetadataPurpose {
128 : static String Usermedia = 'm.usermedia';
129 : static String Screenshare = 'm.screenshare';
130 : }
131 :
132 : class SDPStreamMetadata {
133 : Map<String, SDPStreamPurpose> sdpStreamMetadatas;
134 2 : SDPStreamMetadata(this.sdpStreamMetadatas);
135 :
136 0 : factory SDPStreamMetadata.fromJson(Map<String, dynamic> json) =>
137 0 : SDPStreamMetadata(
138 0 : json.map(
139 0 : (key, value) => MapEntry(key, SDPStreamPurpose.fromJson(value)),
140 : ),
141 : );
142 2 : Map<String, dynamic> toJson() =>
143 10 : sdpStreamMetadatas.map((key, value) => MapEntry(key, value.toJson()));
144 : }
145 :
146 : /// MSC3086: Asserted identity on VoIP calls
147 : /// https://github.com/matrix-org/matrix-doc/pull/3086
148 : class AssertedIdentity {
149 : String? id;
150 : String? displayName;
151 : String? avatarUrl;
152 2 : AssertedIdentity({this.id, this.displayName, this.avatarUrl});
153 0 : factory AssertedIdentity.fromJson(Map<String, dynamic> json) =>
154 0 : AssertedIdentity(
155 0 : displayName: json['display_name'] as String?,
156 0 : id: json['id'] as String?,
157 0 : avatarUrl: json['avatar_url'] as String?,
158 : );
159 4 : Map<String, dynamic> toJson() => {
160 6 : if (displayName != null) 'display_name': displayName,
161 6 : if (id != null) 'id': id,
162 2 : if (avatarUrl != null) 'avatar_url': avatarUrl,
163 : };
164 : }
|