diff --git a/lib/src/voip_content.dart b/lib/src/voip_content.dart index 887824c7..6f34969b 100644 --- a/lib/src/voip_content.dart +++ b/lib/src/voip_content.dart @@ -4,20 +4,19 @@ class CallReplacesTarget { String display_name; String avatar_url; - CallReplacesTarget(); - factory CallReplacesTarget.fromJson(Map json) { - return CallReplacesTarget() - ..id = json['id'].toString() - ..display_name = json['display_name'].toString() - ..avatar_url = json['avatar_url'].toString(); - } - Map toJson() { - return { - if (id != null) 'id': id, - if (display_name != null) 'display_name': display_name, - if (avatar_url != null) 'avatar_url': avatar_url, - }; - } + CallReplacesTarget({this.id, this.display_name, this.avatar_url}); + factory CallReplacesTarget.fromJson(Map json) => + CallReplacesTarget( + id: json['id'].toString(), + display_name: json['display_name'].toString(), + avatar_url: json['avatar_url'].toString(), + ); + + Map toJson() => { + if (id != null) 'id': id, + if (display_name != null) 'display_name': display_name, + if (avatar_url != null) 'avatar_url': avatar_url, + }; } /// MSC2747: VoIP call transfers @@ -29,25 +28,28 @@ class CallReplaces { String await_call; String target_room; - CallReplaces(); - factory CallReplaces.fromJson(Map json) { - return CallReplaces() - ..replacement_id = json['replacement_id'].toString() - ..create_call = json['create_call'].toString() - ..await_call = json['await_call'].toString() - ..target_room = json['target_room'].toString() - ..target_user = CallReplacesTarget.fromJson(json['target_user']); - } + CallReplaces({ + this.replacement_id, + this.target_user, + this.create_call, + this.await_call, + this.target_room, + }); + factory CallReplaces.fromJson(Map json) => CallReplaces( + replacement_id: json['replacement_id'].toString(), + create_call: json['create_call'].toString(), + await_call: json['await_call'].toString(), + target_room: json['target_room'].toString(), + target_user: CallReplacesTarget.fromJson(json['target_user']), + ); - Map toJson() { - return { - if (replacement_id != null) 'replacement_id': replacement_id, - if (target_user != null) 'target_user': target_user.toJson(), - if (create_call != null) 'create_call': create_call, - if (await_call != null) 'await_call': await_call, - if (target_room != null) 'target_room': target_room, - }; - } + Map toJson() => { + if (replacement_id != null) 'replacement_id': replacement_id, + if (target_user != null) 'target_user': target_user.toJson(), + if (create_call != null) 'create_call': create_call, + if (await_call != null) 'await_call': await_call, + if (target_room != null) 'target_room': target_room, + }; } // TODO: Change to "sdp_stream_metadata" when MSC3077 is merged @@ -58,18 +60,16 @@ const String sdpStreamMetadataKey = 'org.matrix.msc3077.sdp_stream_metadata'; class CallCapabilities { bool transferee; bool dtmf; - CallCapabilities(); - factory CallCapabilities.fromJson(Map json) { - return CallCapabilities() - ..dtmf = json['m.call.dtmf'] as bool ?? false - ..transferee = json['m.call.transferee'] as bool ?? false; - } - Map toJson() { - return { - if (transferee != null) 'm.call.transferee': transferee, - if (dtmf != null) 'm.call.dtmf': dtmf, - }; - } + CallCapabilities({this.transferee, this.dtmf}); + factory CallCapabilities.fromJson(Map json) => + CallCapabilities( + dtmf: json['m.call.dtmf'] as bool ?? false, + transferee: json['m.call.transferee'] as bool ?? false, + ); + Map toJson() => { + if (transferee != null) 'm.call.transferee': transferee, + if (dtmf != null) 'm.call.dtmf': dtmf, + }; } /// MSC3077: Support for multi-stream VoIP @@ -88,21 +88,19 @@ class SDPStreamPurpose { bool audio_muted; bool video_muted; - SDPStreamPurpose(); - factory SDPStreamPurpose.fromJson(Map json) { - return SDPStreamPurpose() - ..audio_muted = json['audio_muted'] as bool ?? false - ..video_muted = json['video_muted'] as bool ?? false - ..purpose = json['purpose'] as String; - } + SDPStreamPurpose({this.purpose, this.audio_muted, this.video_muted}); + factory SDPStreamPurpose.fromJson(Map json) => + SDPStreamPurpose( + audio_muted: json['audio_muted'] as bool ?? false, + video_muted: json['video_muted'] as bool ?? false, + purpose: json['purpose'] as String, + ); - Map toJson() { - return { - 'purpose': purpose, - if (audio_muted != null) 'audio_muted': audio_muted, - if (video_muted != null) 'video_muted': video_muted, - }; - } + Map toJson() => { + 'purpose': purpose, + if (audio_muted != null) 'audio_muted': audio_muted, + if (video_muted != null) 'video_muted': video_muted, + }; } class SDPStreamMetadataPurpose { @@ -114,14 +112,11 @@ class SDPStreamMetadata { Map sdpStreamMetadatas; SDPStreamMetadata(this.sdpStreamMetadatas); - factory SDPStreamMetadata.fromJson(Map json) { - return SDPStreamMetadata(json - .map((key, value) => MapEntry(key, SDPStreamPurpose.fromJson(value)))); - } - Map toJson() { - return sdpStreamMetadatas - .map((key, value) => MapEntry(key, value.toJson())); - } + factory SDPStreamMetadata.fromJson(Map json) => + SDPStreamMetadata(json.map( + (key, value) => MapEntry(key, SDPStreamPurpose.fromJson(value)))); + Map toJson() => + sdpStreamMetadatas.map((key, value) => MapEntry(key, value.toJson())); } /// MSC3086: Asserted identity on VoIP calls @@ -130,19 +125,16 @@ class AssertedIdentity { String id; String displayName; String avatarUrl; - AssertedIdentity(); - factory AssertedIdentity.fromJson(Map json) { - return AssertedIdentity() - ..displayName = json['display_name'] as String - ..id = json['id'] as String - ..avatarUrl = json['avatar_url'] as String; - } - Map toJson() { - return { - if (displayName != null) 'display_name': displayName, - if (id != null) 'id': id, - if (avatarUrl != null) 'avatar_url': avatarUrl, - }; - } + AssertedIdentity({this.id, this.displayName, this.avatarUrl}); + factory AssertedIdentity.fromJson(Map json) => + AssertedIdentity( + displayName: json['display_name'] as String, + id: json['id'] as String, + avatarUrl: json['avatar_url'] as String, + ); + Map toJson() => { + if (displayName != null) 'display_name': displayName, + if (id != null) 'id': id, + if (avatarUrl != null) 'avatar_url': avatarUrl, + }; } -