Skip to content

Commit

Permalink
FLUT-217: Added skip preview capabilities based on layout API (#1726)
Browse files Browse the repository at this point in the history
* Added skip preview option using layout API

* Added meeting flow file

* Fixed skip preview bugs

* Updated podfile

* 🤖 Automated Format and Fix

* released sample app version 1.5.153 (453) 🍀

* updated changelog

---------

Co-authored-by: Decoder07 <[email protected]>
Co-authored-by: Yogesh Singh <[email protected]>
  • Loading branch information
3 people authored Mar 11, 2024
1 parent 8b06aa1 commit 1f80603
Show file tree
Hide file tree
Showing 21 changed files with 762 additions and 740 deletions.
17 changes: 9 additions & 8 deletions packages/hms_room_kit/lib/src/layout_api/hms_room_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,19 @@ class ScreenElements {
class Preview {
final ScreenElements? previewHeader;
final JoinForm? joinForm;
final bool? skipPreviewScreen;

Preview({
this.previewHeader,
this.joinForm,
});
Preview({this.previewHeader, this.joinForm, this.skipPreviewScreen = false});

factory Preview.fromJson(Map<String, dynamic>? json) {
if (json == null) {
return Preview();
}
return Preview(
previewHeader: ScreenElements.fromJson(json['preview_header']),
joinForm: JoinForm.fromJson(json['join_form']),
);
previewHeader: ScreenElements.fromJson(
json['default']?['elements']?['preview_header']),
joinForm: JoinForm.fromJson(json['default']?['elements']?['join_form']),
skipPreviewScreen: json["skip_preview_screen"]);
}
}

Expand Down Expand Up @@ -126,7 +125,7 @@ class Screens {
}
return Screens(
preview: json.containsKey('preview') == true
? Preview.fromJson(json['preview']?['default']?['elements'])
? Preview.fromJson(json['preview'])
: null,
conferencing: json.containsKey('conferencing') == true
? Conferencing.fromJson(json['conferencing'])
Expand Down Expand Up @@ -220,6 +219,7 @@ class HMSRoomLayout {
static bool isBRBEnabled = true;
static List<String>? offStageRoles = [];
static bool skipPreviewForRole = false;
static bool skipPreview = false;

static Future<void> getRoomLayout(
{required HMSSDKInteractor hmsSDKInteractor,
Expand Down Expand Up @@ -255,6 +255,7 @@ class HMSRoomLayout {
peerType = roleLayoutData?.screens?.conferencing?.hlsLiveStreaming != null
? PeerRoleType.hlsViewer
: PeerRoleType.conferencing;
skipPreview = roleLayoutData?.screens?.preview?.skipPreviewScreen ?? false;
if (peerType == PeerRoleType.conferencing) {
chatData =
roleLayoutData?.screens?.conferencing?.defaultConf?.elements?.chat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ class MeetingGridComponent extends StatelessWidget {
Widget build(BuildContext context) {
return Selector<
MeetingStore,
Tuple6<List<PeerTrackNode>, bool, int, int, MeetingMode,
PeerTrackNode?>>(
selector: (_, meetingStore) => Tuple6(
Tuple7<List<PeerTrackNode>, bool, int, int, MeetingMode,
PeerTrackNode?, int>>(
selector: (_, meetingStore) => Tuple7(
meetingStore.peerTracks,
meetingStore.isHLSLink,
meetingStore.peerTracks.length,
meetingStore.screenShareCount,
meetingStore.meetingMode,
meetingStore.peerTracks.isNotEmpty
? meetingStore.peerTracks[meetingStore.screenShareCount]
: null),
: null,
meetingStore.viewControllers.length),
builder: (_, data, __) {
if (data.item3 == 0) {
if (data.item3 == 0 || data.item7 == 0) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
Expand Down
47 changes: 36 additions & 11 deletions packages/hms_room_kit/lib/src/meeting/meeting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import 'package:tuple/tuple.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';

///Project imports
import 'package:hms_room_kit/src/widgets/common_widgets/hms_hls_starting_overlay.dart';
import 'package:hms_room_kit/src/layout_api/hms_room_layout.dart' as HMSTheme;
import 'package:hms_room_kit/src/widgets/toasts/toast_widget.dart';
import 'package:hms_room_kit/hms_room_kit.dart';
import 'package:hms_room_kit/src/meeting/meeting_grid_component.dart';
Expand Down Expand Up @@ -67,6 +69,14 @@ class _MeetingPageState extends State<MeetingPage> {
context.read<MeetingStore>().initForegroundTask();
}

bool showError(int? errorCode) {
if (errorCode != null) {
List<int> errorCodes = [1003, 2000, 4005, 424, 404];
return errorCodes.contains(errorCode);
}
return false;
}

@override
Widget build(BuildContext context) {
return WillPopScope(
Expand Down Expand Up @@ -382,24 +392,39 @@ class _MeetingPageState extends State<MeetingPage> {
}
return const SizedBox();
}),
if (HMSTheme
.HMSRoomLayout
.roleLayoutData
?.screens
?.preview
?.joinForm
?.joinBtnType ==
HMSTheme.JoinButtonType
.JOIN_BTN_TYPE_JOIN_AND_GO_LIVE)
Selector<MeetingStore,
Tuple2<bool, int>>(
selector: (_, meetingStore) =>
Tuple2(
meetingStore
.isHLSStarting,
meetingStore
.peerTracks.length),
builder: (_, hlsData, __) {
return (!hlsData.item1 ||
hlsData.item2 == 0)
? const SizedBox()
: HMSHLSStartingOverlay();
}),
if (failureErrors.item2 != null)
if (failureErrors.item2?.code?.errorCode == 1003 ||
failureErrors.item2?.code
?.errorCode ==
2000 ||
failureErrors.item2?.code
?.errorCode ==
4005 ||
failureErrors.item2?.code
?.errorCode ==
424)
if (showError(failureErrors
.item2?.code?.errorCode))
UtilityComponents
.showFailureError(
failureErrors.item2!,
context,
() => context
.read<MeetingStore>()
.leave())
.leave()),
],
),
),
Expand Down
78 changes: 38 additions & 40 deletions packages/hms_room_kit/lib/src/meeting/meeting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MeetingStore extends ChangeNotifier

bool hasHlsStarted = false;

bool isHLSLoading = false;
bool isHLSStarting = false;

String? streamUrl = "";

Expand Down Expand Up @@ -264,48 +264,31 @@ class MeetingStore extends ChangeNotifier
///List of bottom sheets currently open
List<BuildContext> bottomSheets = [];

Future<HMSException?> join(String userName, {HMSConfig? roomConfig}) async {
//If roomConfig is null then only we call the methods to get the authToken
//If we are joining the room from preview we already have authToken so we don't
//need to call the getAuthTokenByRoomCode method
if (roomConfig == null) {
//We use this to get the auth token from room code
dynamic tokenData;

if (Constant.roomCode != null) {
tokenData = await _hmsSDKInteractor.getAuthTokenByRoomCode(
userId: Constant.prebuiltOptions?.userId,
roomCode: Constant.roomCode!,
endPoint: Constant.tokenEndPoint);
} else {
tokenData = Constant.authToken;
}
Future<HMSException?> join(String userName, String? tokenData) async {
late HMSConfig joinConfig;

///If the tokenData is String then we set the authToken in the roomConfig
///and then we join the room
///
///If the tokenData is HMSException then we return the HMSException i.e. tokenData
if ((tokenData is String?) && tokenData != null) {
///Success Scenario
roomConfig = HMSConfig(
authToken: tokenData,
userName: userName,
captureNetworkQualityInPreview: true,
endPoint: Constant.initEndPoint);
} else {
///Error Scenario
return tokenData;
}
///Here we create the config using tokenData and userName
if (tokenData != null) {
joinConfig = HMSConfig(
authToken: tokenData,
userName: userName,
// endPoint is only required by 100ms Team. Client developers should not use `endPoint`
//This is only for 100ms internal testing, endPoint can be safely removed from
//the HMSConfig for external usage
endPoint: Constant.initEndPoint);
}

_hmsSDKInteractor.addUpdateListener(this);
_hmsSDKInteractor.addLogsListener(this);
HMSPollInteractivityCenter.addPollUpdateListener(listener: this);
HMSHLSPlayerController.addHMSHLSPlaybackEventsListener(this);

if (HMSRoomLayout.peerType == PeerRoleType.hlsViewer) {
HMSHLSPlayerController.addHMSHLSPlaybackEventsListener(this);
}
WidgetsBinding.instance.addObserver(this);
setMeetingModeUsingLayoutApi();
_hmsSDKInteractor.join(config: roomConfig);
setRecipientSelectorValue();
_hmsSDKInteractor.join(config: joinConfig);
return null;
}

Expand Down Expand Up @@ -477,6 +460,9 @@ class MeetingStore extends ChangeNotifier
toasts.removeWhere((toast) =>
(toast.hmsToastType == HMSToastsType.pollStartedToast) &&
(toast.toastData.poll.pollId == data));
case HMSToastsType.streamingErrorToast:
toasts.removeWhere(
(toast) => toast.hmsToastType == HMSToastsType.streamingErrorToast);
}
notifyListeners();
}
Expand Down Expand Up @@ -899,9 +885,17 @@ class MeetingStore extends ChangeNotifier
}
getCurrentAudioDevice();
getAudioDevicesList();
notifyListeners();
setViewControllers();
notifyListeners();
fetchPollList(HMSPollState.stopped);

if (HMSRoomLayout.roleLayoutData?.screens?.preview?.joinForm?.joinBtnType ==
JoinButtonType.JOIN_BTN_TYPE_JOIN_AND_GO_LIVE &&
!hasHlsStarted) {
isHLSStarting = true;
notifyListeners();
startHLSStreaming(false, false);
}
// if (Platform.isIOS &&
// HMSRoomLayout.roleLayoutData?.screens?.conferencing?.defaultConf !=
// null) {
Expand Down Expand Up @@ -956,7 +950,7 @@ class MeetingStore extends ChangeNotifier

@override
void onRoomUpdate({required HMSRoom room, required HMSRoomUpdate update}) {
log("onRoomUpdate-> room: ${room.toString()} update: ${update.name}");
log("meeting onRoomUpdate-> room: ${room.toString()} update: ${update.name}");
peersInRoom = room.peerCount;
switch (update) {
case HMSRoomUpdate.browserRecordingStateUpdated:
Expand All @@ -976,7 +970,8 @@ class MeetingStore extends ChangeNotifier
room.hmsRtmpStreamingState?.state ?? HMSStreamingState.none;
break;
case HMSRoomUpdate.hlsStreamingStateUpdated:
isHLSLoading = false;
isHLSStarting =
room.hmshlsStreamingState?.state == HMSStreamingState.starting;
streamingType["hls"] =
room.hmshlsStreamingState?.state ?? HMSStreamingState.none;
hasHlsStarted =
Expand Down Expand Up @@ -1553,7 +1548,7 @@ class MeetingStore extends ChangeNotifier
case HMSPeerUpdate.roleUpdated:
if (peer.isLocal) {
removeAllBottomSheets();
getSpotlightPeer();
// getSpotlightPeer();
setPreviousRole(localPeer?.role.name ?? "");
resetLayout(peer.role.name);
localPeer = peer;
Expand Down Expand Up @@ -1802,7 +1797,7 @@ class MeetingStore extends ChangeNotifier
_hmsSessionStore?.addKeyChangeListener(
keys: SessionStoreKeyValues.getSessionStoreKeys(),
hmsKeyChangeListener: this);
getSpotlightPeer();
// getSpotlightPeer();
}

///We get this call everytime metadata corresponding to a key is changed
Expand Down Expand Up @@ -2441,7 +2436,6 @@ class MeetingStore extends ChangeNotifier
}
break;
case HMSActionResultListenerMethod.hlsStreamingStarted:
isHLSLoading = true;
hlsStreamingRetry = false;
notifyListeners();
break;
Expand Down Expand Up @@ -2544,6 +2538,10 @@ class MeetingStore extends ChangeNotifier
case HMSActionResultListenerMethod.sendDirectMessage:
break;
case HMSActionResultListenerMethod.hlsStreamingStarted:
isHLSStarting = false;
toasts.add(HMSToastModel(hmsException,
hmsToastType: HMSToastsType.streamingErrorToast));
notifyListeners();
break;
case HMSActionResultListenerMethod.hlsStreamingStopped:
break;
Expand Down
Loading

0 comments on commit 1f80603

Please sign in to comment.