From 50d97ebeb224dcbfa8e306b8cb50adcaee12d4db Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sat, 15 Aug 2020 16:05:11 +0200 Subject: [PATCH] Fix unencrypted call events --- lib/src/client.dart | 19 +++++++------ lib/src/room.dart | 65 +++++++++++++++++++++++++++++++-------------- 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index e625d458..f234ac8f 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -981,14 +981,17 @@ class Client extends MatrixApi { } onEvent.add(update); - if (event['type'] == EventTypes.CallInvite) { - onCallInvite.add(Event.fromJson(event, room, sortOrder)); - } else if (event['type'] == EventTypes.CallHangup) { - onCallHangup.add(Event.fromJson(event, room, sortOrder)); - } else if (event['type'] == EventTypes.CallAnswer) { - onCallAnswer.add(Event.fromJson(event, room, sortOrder)); - } else if (event['type'] == EventTypes.CallCandidates) { - onCallCandidates.add(Event.fromJson(event, room, sortOrder)); + final rawUnencryptedEvent = update.content; + + if (rawUnencryptedEvent['type'] == EventTypes.CallInvite) { + onCallInvite.add(Event.fromJson(rawUnencryptedEvent, room, sortOrder)); + } else if (rawUnencryptedEvent['type'] == EventTypes.CallHangup) { + onCallHangup.add(Event.fromJson(rawUnencryptedEvent, room, sortOrder)); + } else if (rawUnencryptedEvent['type'] == EventTypes.CallAnswer) { + onCallAnswer.add(Event.fromJson(rawUnencryptedEvent, room, sortOrder)); + } else if (rawUnencryptedEvent['type'] == EventTypes.CallCandidates) { + onCallCandidates + .add(Event.fromJson(rawUnencryptedEvent, room, sortOrder)); } } } diff --git a/lib/src/room.dart b/lib/src/room.dart index 943fe89e..2ebcfd18 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1349,16 +1349,22 @@ class Room { {String type = 'offer', int version = 0, String txid}) async { txid ??= 'txid${DateTime.now().millisecondsSinceEpoch}'; + final content = { + 'call_id': callId, + 'lifetime': lifetime, + 'offer': {'sdp': sdp, 'type': type}, + 'version': version, + }; + + final sendMessageContent = encrypted && client.encryptionEnabled + ? await client.encryption.encryptGroupMessagePayload(id, content, + type: EventTypes.CallInvite) + : content; return await client.sendMessage( id, EventTypes.CallInvite, txid, - { - 'call_id': callId, - 'lifetime': lifetime, - 'offer': {'sdp': sdp, 'type': type}, - 'version': version, - }, + sendMessageContent, ); } @@ -1387,15 +1393,21 @@ class Room { String txid, }) async { txid ??= 'txid${DateTime.now().millisecondsSinceEpoch}'; + final content = { + 'call_id': callId, + 'candidates': candidates, + 'version': version, + }; + + final sendMessageContent = encrypted && client.encryptionEnabled + ? await client.encryption.encryptGroupMessagePayload(id, content, + type: EventTypes.CallCandidates) + : content; return await client.sendMessage( id, EventTypes.CallCandidates, txid, - { - 'call_id': callId, - 'candidates': candidates, - 'version': version, - }, + sendMessageContent, ); } @@ -1407,15 +1419,21 @@ class Room { Future answerCall(String callId, String sdp, {String type = 'answer', int version = 0, String txid}) async { txid ??= 'txid${DateTime.now().millisecondsSinceEpoch}'; + final content = { + 'call_id': callId, + 'answer': {'sdp': sdp, 'type': type}, + 'version': version, + }; + + final sendMessageContent = encrypted && client.encryptionEnabled + ? await client.encryption.encryptGroupMessagePayload(id, content, + type: EventTypes.CallAnswer) + : content; return await client.sendMessage( id, EventTypes.CallAnswer, txid, - { - 'call_id': callId, - 'answer': {'sdp': sdp, 'type': type}, - 'version': version, - }, + sendMessageContent, ); } @@ -1425,14 +1443,21 @@ class Room { Future hangupCall(String callId, {int version = 0, String txid}) async { txid ??= 'txid${DateTime.now().millisecondsSinceEpoch}'; + + final content = { + 'call_id': callId, + 'version': version, + }; + + final sendMessageContent = encrypted && client.encryptionEnabled + ? await client.encryption.encryptGroupMessagePayload(id, content, + type: EventTypes.CallHangup) + : content; return await client.sendMessage( id, EventTypes.CallHangup, txid, - { - 'call_id': callId, - 'version': version, - }, + sendMessageContent, ); }