Skip to content

Commit

Permalink
Fixed recording pause bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Decoder07 committed Dec 13, 2023
1 parent ed2a1f2 commit 4c8c75c
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 79 deletions.
45 changes: 32 additions & 13 deletions packages/hms_room_kit/lib/src/hls_viewer/hls_viewer_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ class HLSViewerHeader extends StatelessWidget {
///If the HLS streaming is not started we show nothing
Selector<MeetingStore, bool>(
selector: (_, meetingStore) =>
meetingStore.streamingType['hls'] ?? false,
(meetingStore.streamingType['hls'] ==
HMSStreamingState.started ||
meetingStore.streamingType['rtmp'] ==
HMSStreamingState.started),
builder: (_, isHLSStarted, __) {
return isHLSStarted
? Container(
Expand Down Expand Up @@ -99,15 +102,24 @@ class HLSViewerHeader extends StatelessWidget {
///If the recording is not started we show nothing
///
///If recording initialising state is true we show the loader
Selector<MeetingStore,
Tuple4<bool, bool, bool, HMSRecordingState>>(
selector: (_, meetingStore) => Tuple4(
meetingStore.recordingType["browser"] ?? false,
meetingStore.recordingType["server"] ?? false,
meetingStore.recordingType["hls"] ?? false,
meetingStore.hmsRecordingState),
Selector<
MeetingStore,
Tuple3<HMSRecordingState, HMSRecordingState,
HMSRecordingState>>(
selector: (_, meetingStore) => Tuple3(
meetingStore.recordingType["browser"] ??
HMSRecordingState.none,
meetingStore.recordingType["server"] ??
HMSRecordingState.none,
meetingStore.recordingType["hls"] ??
HMSRecordingState.none),
builder: (_, data, __) {
return (data.item1 || data.item2 || data.item3)
return (data.item1 == HMSRecordingState.started ||
data.item1 == HMSRecordingState.resumed ||
data.item2 == HMSRecordingState.started ||
data.item2 == HMSRecordingState.resumed ||
data.item3 == HMSRecordingState.started ||
data.item3 == HMSRecordingState.resumed)
? SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/record.svg",
height: 24,
Expand All @@ -116,15 +128,19 @@ class HLSViewerHeader extends StatelessWidget {
HMSThemeColors.alertErrorDefault,
BlendMode.srcIn),
)
: data.item4 == HMSRecordingState.starting
: (data.item1 == HMSRecordingState.starting ||
data.item2 == HMSRecordingState.starting ||
data.item3 == HMSRecordingState.starting)
? SizedBox(
height: 24,
width: 24,
child: CircularProgressIndicator(
strokeWidth: 1,
color: HMSThemeColors.onSurfaceHighEmphasis,
))
: data.item4 == HMSRecordingState.paused
: (data.item1 == HMSRecordingState.paused ||
data.item2 == HMSRecordingState.paused ||
data.item3 == HMSRecordingState.paused)
? SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/recording_paused.svg",
height: 24,
Expand All @@ -140,11 +156,14 @@ class HLSViewerHeader extends StatelessWidget {
),

///This renders the number of peers
///If the HLS streaming is started, we render the number of peers
///If the HLS or RTMP streaming is started, we render the number of peers
///else we render an empty Container
Selector<MeetingStore, Tuple2<bool, int>>(
selector: (_, meetingStore) => Tuple2(
meetingStore.streamingType['hls'] ?? false,
meetingStore.streamingType['hls'] ==
HMSStreamingState.started ||
meetingStore.streamingType['rtmp'] ==
HMSStreamingState.started,
meetingStore.peersInRoom),
builder: (_, data, __) {
return data.item1
Expand Down
55 changes: 42 additions & 13 deletions packages/hms_room_kit/lib/src/meeting/meeting_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ class _MeetingHeaderState extends State<MeetingHeader> {
///If recording initialising state is true we show the loader
Selector<MeetingStore, bool>(
selector: (_, meetingStore) =>
meetingStore.streamingType['hls'] ?? false,
(meetingStore.streamingType['hls'] ==
HMSStreamingState.started ||
meetingStore.streamingType['rtmp'] ==
HMSStreamingState.started),
builder: (_, isHLSStarted, __) {
return isHLSStarted
? Container(
Expand Down Expand Up @@ -115,16 +118,29 @@ class _MeetingHeaderState extends State<MeetingHeader> {
///else we render an empty Container
///
///For recording status we use the recordingType map from the [MeetingStore]
Selector<MeetingStore,
Tuple4<bool, bool, bool, HMSRecordingState>>(
selector: (_, meetingStore) => Tuple4(
Selector<
MeetingStore,
Tuple3<HMSRecordingState, HMSRecordingState,
HMSRecordingState>>(
selector: (_, meetingStore) => Tuple3(
meetingStore.recordingType["browser"] ??
false,
meetingStore.recordingType["server"] ?? false,
meetingStore.recordingType["hls"] ?? false,
meetingStore.hmsRecordingState),
HMSRecordingState.none,
meetingStore.recordingType["server"] ??
HMSRecordingState.none,
meetingStore.recordingType["hls"] ??
HMSRecordingState.none),
builder: (_, data, __) {
return (data.item1 || data.item2 || data.item3)
return (data.item1 ==
HMSRecordingState.started ||
data.item1 ==
HMSRecordingState.resumed ||
data.item2 ==
HMSRecordingState.started ||
data.item2 ==
HMSRecordingState.resumed ||
data.item3 ==
HMSRecordingState.started ||
data.item3 == HMSRecordingState.resumed)
? SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/record.svg",
height: 24,
Expand All @@ -133,7 +149,12 @@ class _MeetingHeaderState extends State<MeetingHeader> {
HMSThemeColors.alertErrorDefault,
BlendMode.srcIn),
)
: data.item4 == HMSRecordingState.starting
: (data.item1 ==
HMSRecordingState.starting ||
data.item2 ==
HMSRecordingState.starting ||
data.item3 ==
HMSRecordingState.starting)
? SizedBox(
height: 20,
width: 20,
Expand All @@ -142,14 +163,19 @@ class _MeetingHeaderState extends State<MeetingHeader> {
color: HMSThemeColors
.onSurfaceHighEmphasis,
))
: data.item4 == HMSRecordingState.paused
: (data.item1 ==
HMSRecordingState.paused ||
data.item2 ==
HMSRecordingState.paused ||
data.item3 ==
HMSRecordingState.paused)
? SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/recording_paused.svg",
height: 24,
width: 24,
colorFilter: ColorFilter.mode(
HMSThemeColors
.alertErrorDefault,
.onSurfaceHighEmphasis,
BlendMode.srcIn),
)
: Container();
Expand All @@ -163,7 +189,10 @@ class _MeetingHeaderState extends State<MeetingHeader> {
///else we render an empty Container
Selector<MeetingStore, Tuple2<bool, int>>(
selector: (_, meetingStore) => Tuple2(
meetingStore.streamingType['hls'] ?? false,
((meetingStore.streamingType['hls'] ==
HMSStreamingState.started) ||
(meetingStore.streamingType['rtmp'] ==
HMSStreamingState.started)),
meetingStore.peersInRoom),
builder: (_, data, __) {
return data.item1
Expand Down
59 changes: 28 additions & 31 deletions packages/hms_room_kit/lib/src/meeting/meeting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ class MeetingStore extends ChangeNotifier

List<HMSToastModel> toasts = [];

Map<String, bool> recordingType = {
"browser": false,
"server": false,
"hls": false
Map<String, HMSRecordingState> recordingType = {
"browser": HMSRecordingState.none,
"server": HMSRecordingState.none,
"hls": HMSRecordingState.none
};

Map<String, bool> streamingType = {"rtmp": false, "hls": false};
Map<String, HMSStreamingState> streamingType = {
"rtmp": HMSStreamingState.none,
"hls": HMSStreamingState.none
};

String description = "Meeting Ended";

Expand Down Expand Up @@ -228,9 +231,6 @@ class MeetingStore extends ChangeNotifier
///This stores the number of peers in the room
int peersInRoom = 0;

///Check whether recording is in intialising state
HMSRecordingState hmsRecordingState = HMSRecordingState.none;

///Pool of video views
List<HMSTextureViewController> viewControllers = [];

Expand Down Expand Up @@ -529,7 +529,8 @@ class MeetingStore extends ChangeNotifier
meetingUrl: meetingUrl, toRecord: toRecord, rtmpUrls: rtmpUrls);

_hmsSDKInteractor.startRtmpOrRecording(hmsRecordingConfig, this);
hmsRecordingState = HMSRecordingState.starting;
recordingType["browser"] = HMSRecordingState.starting;

notifyListeners();
}

Expand Down Expand Up @@ -774,21 +775,19 @@ class MeetingStore extends ChangeNotifier
} else {
hasHlsStarted = false;
}
if (room.hmsBrowserRecordingState?.state == HMSRecordingState.started) {
recordingType["browser"] = true;
}
if (room.hmsServerRecordingState?.state == HMSRecordingState.started) {
recordingType["server"] = true;
}
if (room.hmshlsRecordingState?.state == HMSRecordingState.started) {
recordingType["hls"] = true;
}
if (room.hmsRtmpStreamingState?.state == HMSStreamingState.started) {
streamingType["rtmp"] = true;
}
if (room.hmshlsStreamingState?.state == HMSStreamingState.started) {
streamingType["hls"] = true;
}

recordingType["browser"] =
room.hmsBrowserRecordingState?.state ?? HMSRecordingState.none;
recordingType["server"] =
room.hmsServerRecordingState?.state ?? HMSRecordingState.none;
recordingType["hls"] =
room.hmshlsRecordingState?.state ?? HMSRecordingState.none;

streamingType["rtmp"] =
room.hmsRtmpStreamingState?.state ?? HMSStreamingState.none;
streamingType["hls"] =
room.hmshlsStreamingState?.state ?? HMSStreamingState.none;

setParticipantsList(roles);
for (HMSPeer each in room.peers!) {
if (each.isLocal) {
Expand Down Expand Up @@ -897,26 +896,24 @@ class MeetingStore extends ChangeNotifier
switch (update) {
case HMSRoomUpdate.browserRecordingStateUpdated:
recordingType["browser"] =
room.hmsBrowserRecordingState?.state == HMSRecordingState.started;
hmsRecordingState =
room.hmsBrowserRecordingState?.state ?? HMSRecordingState.none;
break;
case HMSRoomUpdate.serverRecordingStateUpdated:
recordingType["server"] =
room.hmsServerRecordingState?.state == HMSRecordingState.started;
room.hmsServerRecordingState?.state ?? HMSRecordingState.none;
break;
case HMSRoomUpdate.hlsRecordingStateUpdated:
recordingType["hls"] =
room.hmshlsRecordingState?.state == HMSRecordingState.started;
room.hmshlsRecordingState?.state ?? HMSRecordingState.none;
break;
case HMSRoomUpdate.rtmpStreamingStateUpdated:
streamingType["rtmp"] =
room.hmsRtmpStreamingState?.state == HMSStreamingState.started;
room.hmsRtmpStreamingState?.state ?? HMSStreamingState.none;
break;
case HMSRoomUpdate.hlsStreamingStateUpdated:
isHLSLoading = false;
streamingType["hls"] =
room.hmshlsStreamingState?.state == HMSStreamingState.started;
room.hmshlsStreamingState?.state ?? HMSStreamingState.none;
hasHlsStarted =
room.hmshlsStreamingState?.state == HMSStreamingState.started;
streamUrl = hasHlsStarted
Expand Down Expand Up @@ -2193,7 +2190,7 @@ class MeetingStore extends ChangeNotifier
case HMSActionResultListenerMethod.startRtmpOrRecording:
toasts.add(HMSToastModel(hmsException,
hmsToastType: HMSToastsType.errorToast));
hmsRecordingState = HMSRecordingState.failed;
recordingType["browser"] = HMSRecordingState.failed;
notifyListeners();
break;
case HMSActionResultListenerMethod.stopRtmpAndRecording:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:developer';
import 'package:flutter/cupertino.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hms_room_kit/hms_room_kit.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';

Expand Down Expand Up @@ -59,7 +60,8 @@ class _PreviewForRoleHeaderState extends State<PreviewForRoleHeader> {
///If the HLS streaming is not started we show nothing
Selector<MeetingStore, bool>(
selector: (_, meetingStore) =>
meetingStore.streamingType['hls'] ?? false,
meetingStore.streamingType['hls'] ==
HMSStreamingState.started,
builder: (_, isHLSStrted, __) {
return isHLSStrted
? Container(
Expand All @@ -86,14 +88,22 @@ class _PreviewForRoleHeaderState extends State<PreviewForRoleHeader> {
///We render the recording icon based on the recording status
///If the recording is started we show the recording icon
///If the recording is not started we show nothing
Selector<MeetingStore, Tuple3<bool, bool, bool>>(
Selector<
MeetingStore,
Tuple3<HMSRecordingState, HMSRecordingState,
HMSRecordingState>>(
selector: (_, meetingStore) => Tuple3(
meetingStore.recordingType["browser"] ?? false,
meetingStore.recordingType["server"] ?? false,
meetingStore.recordingType["hls"] ?? false,
meetingStore.recordingType["browser"] ??
HMSRecordingState.none,
meetingStore.recordingType["server"] ??
HMSRecordingState.none,
meetingStore.recordingType["hls"] ??
HMSRecordingState.none,
),
builder: (_, data, __) {
return (data.item1 || data.item2 || data.item3)
return (data.item1 == HMSRecordingState.started ||
data.item2 == HMSRecordingState.started ||
data.item3 == HMSRecordingState.started)
? SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/record.svg",
height: 24,
Expand All @@ -109,11 +119,14 @@ class _PreviewForRoleHeaderState extends State<PreviewForRoleHeader> {
),

///This renders the number of peers
///If the HLS streaming is started, we render the number of peers
///If the HLS or RTMP streaming is started, we render the number of peers
///else we render an empty Container
Selector<MeetingStore, Tuple2<bool, int>>(
selector: (_, meetingStore) => Tuple2(
meetingStore.streamingType['hls'] ?? false,
meetingStore.streamingType['hls'] ==
HMSStreamingState.started ||
meetingStore.streamingType['rtmp'] ==
HMSStreamingState.started,
meetingStore.peersInRoom),
builder: (_, data, __) {
return data.item1
Expand Down
Loading

0 comments on commit 4c8c75c

Please sign in to comment.