Skip to content

Commit

Permalink
Added PIP Support based on parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Decoder07 committed Sep 22, 2023
1 parent 70fb9d3 commit 87588fc
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 31 deletions.
3 changes: 3 additions & 0 deletions packages/hms_room_kit/lib/src/common/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 6 additions & 1 deletion packages/hms_room_kit/lib/src/hms_prebuilt_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
74 changes: 45 additions & 29 deletions packages/hms_room_kit/lib/src/meeting/meeting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}
}
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1176,7 +1187,7 @@ class MeetingStore extends ChangeNotifier
// Helper Methods

void clearRoomState() async {
// clearPIPState();
clearPIPState();
removeListeners();
toggleAlwaysScreenOn();
_hmsSDKInteractor.destroy();
Expand All @@ -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();
}
}
}

Expand Down Expand Up @@ -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 !=
Expand Down Expand Up @@ -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
Expand All @@ -1792,16 +1805,19 @@ class MeetingStore extends ChangeNotifier
}

Future<bool> 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) {
Expand All @@ -1821,7 +1837,7 @@ class MeetingStore extends ChangeNotifier
{HMSVideoTrack? track,
required String alternativeText,
required List<int> ratio}) async {
if (Platform.isIOS && track != null) {
if (Constant.isPIPAllowed && Platform.isIOS && track != null) {
isPipActive = await isPIPActive();
if (isPipActive) {
HMSIOSPIPController.changeVideoTrack(
Expand All @@ -1837,7 +1853,7 @@ class MeetingStore extends ChangeNotifier

void changePIPWindowTextOnIOS(
{String? text, required List<int> ratio}) async {
if (Platform.isIOS && text != null) {
if (Constant.isPIPAllowed && Platform.isIOS && text != null) {
isPipActive = await isPIPActive();
if (isPipActive) {
HMSIOSPIPController.changeText(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2150,7 +2166,7 @@ class MeetingStore extends ChangeNotifier
lastVideoStatus = true;
}

if (Platform.isAndroid) {
if (Platform.isAndroid && Constant.isPIPAllowed) {
isPipActive = await HMSAndroidPIPController.isActive();
notifyListeners();
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/hms_room_kit/lib/src/screen_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class _ScreenControllerState extends State<ScreenController> {
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!);
Expand Down
1 change: 1 addition & 0 deletions packages/hmssdk_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class _HomePageState extends State<HomePage> {
roomCode: Constant.roomCode,
options: HMSPrebuiltOptions(
endPoints: endPoints,
isPIPAllowed: true,
iOSScreenshareConfig: HMSIOSScreenshareConfig(
appGroup: "group.flutterhms",
preferredExtension:
Expand Down
1 change: 1 addition & 0 deletions packages/hmssdk_flutter/example/lib/qr_code_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class _QRCodeScreenState extends State<QRCodeScreen> {
roomCode: Constant.roomCode,
options: HMSPrebuiltOptions(
endPoints: endPoints,
isPIPAllowed: true,
iOSScreenshareConfig: HMSIOSScreenshareConfig(
appGroup: "group.flutterhms",
preferredExtension:
Expand Down

0 comments on commit 87588fc

Please sign in to comment.