From 0c8472e41d9d59d2774a1c3a2c6ab37f626a667a Mon Sep 17 00:00:00 2001 From: Decoder07 Date: Tue, 7 May 2024 15:38:46 +0530 Subject: [PATCH 1/4] Added onPeerListUpdate callback in preview --- .../lib/src/preview/preview_store.dart | 3 ++ .../hms/hmssdk_flutter/HmssdkFlutterPlugin.kt | 28 +++++++++++++++++++ .../Classes/SwiftHmssdkFlutterPlugin.swift | 23 +++++++++++++++ .../hms_preview_update_listener_method.dart | 3 ++ .../lib/src/model/hms_preview_listener.dart | 9 ++++++ .../lib/src/service/platform_service.dart | 27 ++++++++++++++++++ 6 files changed, 93 insertions(+) diff --git a/packages/hms_room_kit/lib/src/preview/preview_store.dart b/packages/hms_room_kit/lib/src/preview/preview_store.dart index 0dd725855..0854a23f5 100644 --- a/packages/hms_room_kit/lib/src/preview/preview_store.dart +++ b/packages/hms_room_kit/lib/src/preview/preview_store.dart @@ -316,4 +316,7 @@ class PreviewStore extends ChangeNotifier } notifyListeners(); } + + @override + void onPeerListUpdate({required List addedPeers, required List removedPeers}) {} } diff --git a/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/HmssdkFlutterPlugin.kt b/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/HmssdkFlutterPlugin.kt index dc2a40e8c..1ecd8a21c 100644 --- a/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/HmssdkFlutterPlugin.kt +++ b/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/HmssdkFlutterPlugin.kt @@ -1516,6 +1516,34 @@ class HmssdkFlutterPlugin : } } } + + override fun peerListUpdated(addedPeers: ArrayList?, removedPeers: ArrayList?){ + val args = HashMap() + args["event_name"] = "on_peer_list_update" + val parameters = HashMap() + val peersAdded = ArrayList?>() + val peersRemoved = ArrayList?>() + /** + * Here we add peers to the list after parsing the + * peer object + */ + addedPeers?.forEach { peer -> + peersAdded.add(HMSPeerExtension.toDictionary(peer)) + } + + removedPeers?.forEach { peer -> + peersRemoved.add(HMSPeerExtension.toDictionary(peer)) + } + + parameters["added_peers"] = peersAdded + parameters["removed_peers"] = peersRemoved + + args["data"] = parameters + + CoroutineScope(Dispatchers.Main).launch { + previewSink?.success(args) + } + } } /*** diff --git a/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift b/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift index cbd25b182..d5e66b8d4 100644 --- a/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift +++ b/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift @@ -1276,6 +1276,29 @@ public class SwiftHmssdkFlutterPlugin: NSObject, FlutterPlugin, HMSUpdateListene previewEnded = false previewSink?(data) } + + public func peerListUpdate(added: [HMSPeer], removed: [HMSPeer]) { + var parameters = [String: Any]() + + var addedPeers = [Any]() + var removedPeers = [Any]() + + added.forEach { + addedPeers.append(HMSPeerExtension.toDictionary($0)) + } + + removed.forEach { + removedPeers.append(HMSPeerExtension.toDictionary($0)) + } + + parameters["added_peers"] = addedPeers + parameters["removed_peers"] = removedPeers + + let data = ["event_name": "on_peer_list_update", "data": parameters] as [String: Any] + + previewSink?(data) + } + var previewEnded = false public func on(join room: HMSRoom) { previewEnded = true diff --git a/packages/hmssdk_flutter/lib/src/enum/hms_preview_update_listener_method.dart b/packages/hmssdk_flutter/lib/src/enum/hms_preview_update_listener_method.dart index 6fde86e34..9790a350d 100644 --- a/packages/hmssdk_flutter/lib/src/enum/hms_preview_update_listener_method.dart +++ b/packages/hmssdk_flutter/lib/src/enum/hms_preview_update_listener_method.dart @@ -4,6 +4,7 @@ enum HMSPreviewUpdateListenerMethod { onPeerUpdate, onRoomUpdate, onAudioDeviceChanged, + onPeerListUpdate, unknown } @@ -21,6 +22,8 @@ extension HMSPreviewUpdateListenerMethodValues return HMSPreviewUpdateListenerMethod.onRoomUpdate; case 'on_audio_device_changed': return HMSPreviewUpdateListenerMethod.onAudioDeviceChanged; + case 'on_peer_list_update': + return HMSPreviewUpdateListenerMethod.onPeerListUpdate; default: return HMSPreviewUpdateListenerMethod.unknown; } diff --git a/packages/hmssdk_flutter/lib/src/model/hms_preview_listener.dart b/packages/hmssdk_flutter/lib/src/model/hms_preview_listener.dart index 24229d226..4cabc9d82 100644 --- a/packages/hmssdk_flutter/lib/src/model/hms_preview_listener.dart +++ b/packages/hmssdk_flutter/lib/src/model/hms_preview_listener.dart @@ -50,4 +50,13 @@ abstract class HMSPreviewListener { void onAudioDeviceChanged( {HMSAudioDevice? currentAudioDevice, List? availableAudioDevice}); + + ///Upon joining a room with existing peers, onPeerListUpdated will be called with the list of peers present + ///in the room instead of getting onPeerUpdate for each peer in the room. + ///Subsequent peer joins/leaves would be notified via both onPeerUpdate and onPeerListUpdated + /// - Parameters: + /// - addedPeers: List of peers who joined the room + /// - removedPeers: List of peers who left the room + void onPeerListUpdate( + {required List addedPeers, required List removedPeers}); } diff --git a/packages/hmssdk_flutter/lib/src/service/platform_service.dart b/packages/hmssdk_flutter/lib/src/service/platform_service.dart index 959ba0557..a9b01ea4a 100644 --- a/packages/hmssdk_flutter/lib/src/service/platform_service.dart +++ b/packages/hmssdk_flutter/lib/src/service/platform_service.dart @@ -412,6 +412,27 @@ abstract class PlatformService { : null }); break; + case HMSPreviewUpdateListenerMethod.onPeerListUpdate: + List addedPeers = []; + List removedPeers = []; + + if (event.data.containsKey("added_peers") && + event.data["added_peers"] != null) { + for (var peer in event.data["added_peers"]) { + addedPeers.add(HMSPeer.fromMap(peer)); + } + } + + if (event.data.containsKey("removed_peers") && + event.data["removed_peers"] != null) { + for (var peer in event.data["removed_peers"]) { + removedPeers.add(HMSPeer.fromMap(peer)); + } + } + + notifyPreviewListeners(method, + {"added_peers": addedPeers, "removed_peers": removedPeers}); + break; } }); @@ -614,6 +635,12 @@ abstract class PlatformService { availableAudioDevice: arguments["available_audio_device"]); }); break; + case HMSPreviewUpdateListenerMethod.onPeerListUpdate: + previewListeners.forEach((e) { + e.onPeerListUpdate( + addedPeers: arguments["added_peers"], + removedPeers: arguments["removed_peers"]); + }); } } From 1edfad746c1604ca69d5eccd62dc031eb456a45f Mon Sep 17 00:00:00 2001 From: Decoder07 Date: Tue, 7 May 2024 10:11:23 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=A4=96=20Automated=20Format=20and=20F?= =?UTF-8?q?ix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hms_room_kit/lib/src/preview/preview_store.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/hms_room_kit/lib/src/preview/preview_store.dart b/packages/hms_room_kit/lib/src/preview/preview_store.dart index 0854a23f5..92fc10175 100644 --- a/packages/hms_room_kit/lib/src/preview/preview_store.dart +++ b/packages/hms_room_kit/lib/src/preview/preview_store.dart @@ -316,7 +316,9 @@ class PreviewStore extends ChangeNotifier } notifyListeners(); } - + @override - void onPeerListUpdate({required List addedPeers, required List removedPeers}) {} + void onPeerListUpdate( + {required List addedPeers, + required List removedPeers}) {} } From cb9ed27e100157f22cf5c26dc12e9e5c560defc8 Mon Sep 17 00:00:00 2001 From: Decoder07 Date: Tue, 7 May 2024 15:56:54 +0530 Subject: [PATCH 3/4] Merged branch --- .../lib/src/preview/preview_store.dart | 6 ++-- .../Classes/SwiftHmssdkFlutterPlugin.swift | 28 ++++--------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/packages/hms_room_kit/lib/src/preview/preview_store.dart b/packages/hms_room_kit/lib/src/preview/preview_store.dart index 92fc10175..bf6f0cd90 100644 --- a/packages/hms_room_kit/lib/src/preview/preview_store.dart +++ b/packages/hms_room_kit/lib/src/preview/preview_store.dart @@ -318,7 +318,7 @@ class PreviewStore extends ChangeNotifier } @override - void onPeerListUpdate( - {required List addedPeers, - required List removedPeers}) {} + void onPeerListUpdate({required List addedPeers, required List removedPeers}) { + log("onPeerListUpdate -> addedPeers: $addedPeers removedPeers: $removedPeers"); + } } diff --git a/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift b/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift index d5e66b8d4..3fff710f8 100644 --- a/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift +++ b/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift @@ -1277,28 +1277,6 @@ public class SwiftHmssdkFlutterPlugin: NSObject, FlutterPlugin, HMSUpdateListene previewSink?(data) } - public func peerListUpdate(added: [HMSPeer], removed: [HMSPeer]) { - var parameters = [String: Any]() - - var addedPeers = [Any]() - var removedPeers = [Any]() - - added.forEach { - addedPeers.append(HMSPeerExtension.toDictionary($0)) - } - - removed.forEach { - removedPeers.append(HMSPeerExtension.toDictionary($0)) - } - - parameters["added_peers"] = addedPeers - parameters["removed_peers"] = removedPeers - - let data = ["event_name": "on_peer_list_update", "data": parameters] as [String: Any] - - previewSink?(data) - } - var previewEnded = false public func on(join room: HMSRoom) { previewEnded = true @@ -1519,7 +1497,11 @@ public class SwiftHmssdkFlutterPlugin: NSObject, FlutterPlugin, HMSUpdateListene let data = ["event_name": "on_peer_list_update", "data": parameters] as [String: Any] - eventSink?(data) + if(previewEnded){ + eventSink?(data) + }else{ + previewSink?(data) + } } // MARK: - RTC Stats Listeners From d4f430cec436562ad0215013efa286c0e37ec18e Mon Sep 17 00:00:00 2001 From: Decoder07 Date: Tue, 7 May 2024 10:29:11 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A4=96=20Automated=20Format=20and=20F?= =?UTF-8?q?ix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hms_room_kit/lib/src/preview/preview_store.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/hms_room_kit/lib/src/preview/preview_store.dart b/packages/hms_room_kit/lib/src/preview/preview_store.dart index bf6f0cd90..9b2cbe847 100644 --- a/packages/hms_room_kit/lib/src/preview/preview_store.dart +++ b/packages/hms_room_kit/lib/src/preview/preview_store.dart @@ -318,7 +318,9 @@ class PreviewStore extends ChangeNotifier } @override - void onPeerListUpdate({required List addedPeers, required List removedPeers}) { - log("onPeerListUpdate -> addedPeers: $addedPeers removedPeers: $removedPeers"); + void onPeerListUpdate( + {required List addedPeers, + required List removedPeers}) { + log("onPeerListUpdate -> addedPeers: $addedPeers removedPeers: $removedPeers"); } }