Skip to content

Commit

Permalink
Room recording event (#252)
Browse files Browse the repository at this point in the history
* feat: Add room reocording reminder.

* chore: comment for recording event.
  • Loading branch information
cloudwebrtc authored Mar 8, 2023
1 parent 6dc2bf6 commit b63d4bd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
17 changes: 17 additions & 0 deletions example/lib/exts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ extension LKExampleExt on BuildContext {
),
);

Future<bool?> showRecordingStatusChangedDialog(bool isActiveRecording) =>
showDialog<bool>(
context: this,
builder: (ctx) => AlertDialog(
title: const Text('Room recording reminder'),
content: Text(isActiveRecording
? 'Room recording is active.'
: 'Room recording is stoped.'),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, true),
child: const Text('OK'),
),
],
),
);

Future<bool?> showSubscribePermissionDialog() => showDialog<bool>(
context: this,
builder: (ctx) => AlertDialog(
Expand Down
3 changes: 3 additions & 0 deletions example/lib/pages/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class _RoomPageState extends State<RoomPage> {
WidgetsBindingCompatible.instance
?.addPostFrameCallback((timeStamp) => Navigator.pop(context));
})
..on<RoomRecordingStatusChanged>((event) {
context.showRecordingStatusChangedDialog(event.activeRecording);
})
..on<LocalTrackPublishedEvent>((_) => _sortParticipants())
..on<LocalTrackUnpublishedEvent>((_) => _sortParticipants())
..on<DataReceivedEvent>((event) {
Expand Down
14 changes: 14 additions & 0 deletions lib/src/core/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
String? get serverRegion => _serverRegion;
String? _serverRegion;

bool get isRecording => _isRecording;
bool _isRecording = false;

/// a list of participants that are actively speaking, including local participant.
UnmodifiableListView<Participant> get activeSpeakers =>
UnmodifiableListView<Participant>(_activeSpeakers);
Expand Down Expand Up @@ -154,6 +157,12 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
_serverVersion = event.response.serverVersion;
_serverRegion = event.response.serverRegion;

if (_isRecording != event.response.room.activeRecording) {
_isRecording = event.response.room.activeRecording;
emitWhenConnected(
RoomRecordingStatusChanged(activeRecording: _isRecording));
}

logger.fine('[Engine] Received JoinResponse, '
'serverVersion: ${event.response.serverVersion}');

Expand Down Expand Up @@ -262,6 +271,11 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
_metadata = event.room.metadata;
emitWhenConnected(
RoomMetadataChangedEvent(metadata: event.room.metadata));
if (_isRecording != event.room.activeRecording) {
_isRecording = event.room.activeRecording;
emitWhenConnected(
RoomRecordingStatusChanged(activeRecording: _isRecording));
}
})
..on<SignalConnectionStateUpdatedEvent>((event) {
// during reconnection, need to send sync state upon signal connection.
Expand Down
13 changes: 13 additions & 0 deletions lib/src/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ class RoomMetadataChangedEvent with RoomEvent {
String toString() => '${runtimeType}()';
}

/// Room recording status has changed.
/// Emitted by [Room].
class RoomRecordingStatusChanged with RoomEvent {
final bool activeRecording;

const RoomRecordingStatusChanged({
required this.activeRecording,
});

@override
String toString() => '${runtimeType}(activeRecording = $activeRecording)';
}

/// When a new [RemoteParticipant] joins *after* the current participant has connected
/// It will not fire for participants that are already in the room
/// Emitted by [Room].
Expand Down

0 comments on commit b63d4bd

Please sign in to comment.