From 87588fc35b920ad95996ac5622ef3f30e2361d4f Mon Sep 17 00:00:00 2001 From: Decoder07 Date: Fri, 22 Sep 2023 18:13:07 +0530 Subject: [PATCH] Added PIP Support based on parameter --- .../lib/src/common/constants.dart | 3 + .../lib/src/hms_prebuilt_options.dart | 7 +- .../lib/src/meeting/meeting_store.dart | 74 +++++++++++-------- .../lib/src/screen_controller.dart | 2 +- packages/hmssdk_flutter/example/lib/main.dart | 1 + .../example/lib/qr_code_screen.dart | 1 + 6 files changed, 57 insertions(+), 31 deletions(-) diff --git a/packages/hms_room_kit/lib/src/common/constants.dart b/packages/hms_room_kit/lib/src/common/constants.dart index 8e7830968..5464a507e 100644 --- a/packages/hms_room_kit/lib/src/common/constants.dart +++ b/packages/hms_room_kit/lib/src/common/constants.dart @@ -45,6 +45,9 @@ class Constant { ///[Constant.layoutAPIEndPointKey] is the key for the layout api end point static String layoutAPIEndPointKey = "layoutAPIEndPoint"; + ///[Constant.isPIPAllowed] is the flag to enable/disable PIP + static bool isPIPAllowed = false; + ///[Constant.onLeave] is the function that you wish to execute while leaving the room static Function? onLeave; } diff --git a/packages/hms_room_kit/lib/src/hms_prebuilt_options.dart b/packages/hms_room_kit/lib/src/hms_prebuilt_options.dart index 849410299..68f1318bc 100644 --- a/packages/hms_room_kit/lib/src/hms_prebuilt_options.dart +++ b/packages/hms_room_kit/lib/src/hms_prebuilt_options.dart @@ -26,11 +26,16 @@ class HMSPrebuiltOptions { //this config final HMSIOSScreenshareConfig? iOSScreenshareConfig; + ///If true PIP is enabled in the application + ///else it's not.Default value is false + final bool isPIPAllowed; + ///[HMSPrebuiltOptions] is a class that is used to pass the options to the prebuilt HMSPrebuiltOptions( {this.userName, this.userId, this.endPoints, this.debugInfo = false, - this.iOSScreenshareConfig}); + this.iOSScreenshareConfig, + this.isPIPAllowed = false}); } diff --git a/packages/hms_room_kit/lib/src/meeting/meeting_store.dart b/packages/hms_room_kit/lib/src/meeting/meeting_store.dart index 09f0d1ad3..0b049accd 100644 --- a/packages/hms_room_kit/lib/src/meeting/meeting_store.dart +++ b/packages/hms_room_kit/lib/src/meeting/meeting_store.dart @@ -604,6 +604,13 @@ class MeetingStore extends ChangeNotifier previousRole = localPeer?.role.name; if (isRaisedHand) { changeMetadata(); + } else { + ///Setting the previous role + String value = isRaisedHand ? "true" : "false"; + _hmsSDKInteractor.changeMetadata( + metadata: + "{\"isHandRaised\":$value,\"isBRBOn\":false,\"prevRole\":\"$previousRole\"}", + hmsActionResultListener: this); } HMSRoomLayout.resetLayout(hmsRoleChangeRequest.suggestedRole.name); currentRoleChangeRequest = null; @@ -745,15 +752,18 @@ class MeetingStore extends ChangeNotifier getAudioDevicesList(); notifyListeners(); - if (Platform.isIOS && - HMSRoomLayout.roleLayoutData?.screens?.conferencing?.defaultConf != - null) { - HMSIOSPIPController.setup( - autoEnterPip: true, - aspectRatio: [9, 16], - backgroundColor: Colors.black); - } else if (Platform.isAndroid) { - HMSAndroidPIPController.setup(); + ///PIP Only needs to be called when it's enabled from PIP + if (Constant.isPIPAllowed) { + if (Platform.isIOS && + HMSRoomLayout.roleLayoutData?.screens?.conferencing?.defaultConf != + null) { + HMSIOSPIPController.setup( + autoEnterPip: true, + aspectRatio: [9, 16], + backgroundColor: Colors.black); + } else if (Platform.isAndroid) { + HMSAndroidPIPController.setup(aspectRatio: [9, 16]); + } } } @@ -1008,7 +1018,8 @@ class MeetingStore extends ChangeNotifier } // Below code for change track and text in PIP mode iOS and android. - if (updateSpeakers.isNotEmpty) { + //This is only executed if PIP is enabled + if (Constant.isPIPAllowed && updateSpeakers.isNotEmpty) { if (Platform.isIOS && (screenShareCount == 0 || isScreenShareOn)) { if (updateSpeakers[0].peer.videoTrack != null) { changePIPWindowTrackOnIOS( @@ -1176,7 +1187,7 @@ class MeetingStore extends ChangeNotifier // Helper Methods void clearRoomState() async { - // clearPIPState(); + clearPIPState(); removeListeners(); toggleAlwaysScreenOn(); _hmsSDKInteractor.destroy(); @@ -1198,10 +1209,12 @@ class MeetingStore extends ChangeNotifier } void clearPIPState() { - if (Platform.isAndroid) { - HMSAndroidPIPController.destroy(); - } else if (Platform.isIOS) { - HMSIOSPIPController.destroy(); + if (Constant.isPIPAllowed) { + if (Platform.isAndroid) { + HMSAndroidPIPController.destroy(); + } else if (Platform.isIOS) { + HMSIOSPIPController.destroy(); + } } } @@ -1371,7 +1384,7 @@ class MeetingStore extends ChangeNotifier } } - if (peer.isLocal) { + if (peer.isLocal && Constant.isPIPAllowed) { if (Platform.isIOS) { if (HMSRoomLayout .roleLayoutData?.screens?.conferencing?.hlsLiveStreaming != @@ -1781,7 +1794,7 @@ class MeetingStore extends ChangeNotifier void enterPipModeOnAndroid() async { //to check whether pip is available in android - if (Platform.isAndroid) { + if (Platform.isAndroid && Constant.isPIPAllowed) { bool isPipAvailable = await HMSAndroidPIPController.isAvailable(); if (isPipAvailable) { //[isPipActive] method can also be used to check whether application is in pip Mode or not @@ -1792,16 +1805,19 @@ class MeetingStore extends ChangeNotifier } Future isPIPActive() async { - if (Platform.isAndroid) { - isPipActive = await HMSAndroidPIPController.isActive(); - } else if (Platform.isIOS) { - isPipActive = await HMSIOSPIPController.isActive(); + if (Constant.isPIPAllowed) { + if (Platform.isAndroid) { + isPipActive = await HMSAndroidPIPController.isActive(); + } else if (Platform.isIOS) { + isPipActive = await HMSIOSPIPController.isActive(); + } + return isPipActive; } - return isPipActive; + return false; } void changePIPWindowOnAndroid(String uid) { - if (Platform.isAndroid && isPipActive) { + if (Constant.isPIPAllowed && Platform.isAndroid && isPipActive) { int index = -1; index = peerTracks.indexWhere((element) => element.uid == uid); if (index != -1) { @@ -1821,7 +1837,7 @@ class MeetingStore extends ChangeNotifier {HMSVideoTrack? track, required String alternativeText, required List ratio}) async { - if (Platform.isIOS && track != null) { + if (Constant.isPIPAllowed && Platform.isIOS && track != null) { isPipActive = await isPIPActive(); if (isPipActive) { HMSIOSPIPController.changeVideoTrack( @@ -1837,7 +1853,7 @@ class MeetingStore extends ChangeNotifier void changePIPWindowTextOnIOS( {String? text, required List ratio}) async { - if (Platform.isIOS && text != null) { + if (Constant.isPIPAllowed && Platform.isIOS && text != null) { isPipActive = await isPIPActive(); if (isPipActive) { HMSIOSPIPController.changeText( @@ -2117,7 +2133,7 @@ class MeetingStore extends ChangeNotifier return; } if (state == AppLifecycleState.resumed) { - if (Platform.isAndroid) { + if (Platform.isAndroid && Constant.isPIPAllowed) { isPipActive = await HMSAndroidPIPController.isActive(); } else if (Platform.isIOS) { isPipActive = false; @@ -2150,7 +2166,7 @@ class MeetingStore extends ChangeNotifier lastVideoStatus = true; } - if (Platform.isAndroid) { + if (Platform.isAndroid && Constant.isPIPAllowed) { isPipActive = await HMSAndroidPIPController.isActive(); notifyListeners(); } @@ -2180,12 +2196,12 @@ class MeetingStore extends ChangeNotifier } } } else if (state == AppLifecycleState.inactive) { - if (Platform.isAndroid && !isPipActive) { + if (Constant.isPIPAllowed && Platform.isAndroid && !isPipActive) { isPipActive = await HMSAndroidPIPController.isActive(); } notifyListeners(); } else if (state == AppLifecycleState.detached) { - if (Platform.isAndroid && !isPipActive) { + if (Constant.isPIPAllowed && Platform.isAndroid && !isPipActive) { isPipActive = await HMSAndroidPIPController.isActive(); } notifyListeners(); diff --git a/packages/hms_room_kit/lib/src/screen_controller.dart b/packages/hms_room_kit/lib/src/screen_controller.dart index 83853aeae..747c3e9e0 100644 --- a/packages/hms_room_kit/lib/src/screen_controller.dart +++ b/packages/hms_room_kit/lib/src/screen_controller.dart @@ -49,7 +49,7 @@ class _ScreenControllerState extends State { Constant.prebuiltOptions = widget.options; Constant.roomCode = widget.roomCode; Constant.onLeave = widget.onLeave; - + Constant.isPIPAllowed = widget.options?.isPIPAllowed ?? false; ///Here we set the endPoints if it's non-null if (widget.options?.endPoints != null) { _setEndPoints(widget.options!.endPoints!); diff --git a/packages/hmssdk_flutter/example/lib/main.dart b/packages/hmssdk_flutter/example/lib/main.dart index 7c237aa56..40388b54f 100644 --- a/packages/hmssdk_flutter/example/lib/main.dart +++ b/packages/hmssdk_flutter/example/lib/main.dart @@ -309,6 +309,7 @@ class _HomePageState extends State { roomCode: Constant.roomCode, options: HMSPrebuiltOptions( endPoints: endPoints, + isPIPAllowed: true, iOSScreenshareConfig: HMSIOSScreenshareConfig( appGroup: "group.flutterhms", preferredExtension: diff --git a/packages/hmssdk_flutter/example/lib/qr_code_screen.dart b/packages/hmssdk_flutter/example/lib/qr_code_screen.dart index 7df014c7e..66863e130 100644 --- a/packages/hmssdk_flutter/example/lib/qr_code_screen.dart +++ b/packages/hmssdk_flutter/example/lib/qr_code_screen.dart @@ -79,6 +79,7 @@ class _QRCodeScreenState extends State { roomCode: Constant.roomCode, options: HMSPrebuiltOptions( endPoints: endPoints, + isPIPAllowed: true, iOSScreenshareConfig: HMSIOSScreenshareConfig( appGroup: "group.flutterhms", preferredExtension: