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..9b2cbe847 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,11 @@ class PreviewStore extends ChangeNotifier } notifyListeners(); } + + @override + void onPeerListUpdate( + {required List addedPeers, + required List removedPeers}) { + log("onPeerListUpdate -> addedPeers: $addedPeers removedPeers: $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..3fff710f8 100644 --- a/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift +++ b/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift @@ -1276,6 +1276,7 @@ public class SwiftHmssdkFlutterPlugin: NSObject, FlutterPlugin, HMSUpdateListene previewEnded = false previewSink?(data) } + var previewEnded = false public func on(join room: HMSRoom) { previewEnded = true @@ -1496,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 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"]); + }); } }