diff --git a/example/lib/exts.dart b/example/lib/exts.dart index 03b8567e..6bdcd23c 100644 --- a/example/lib/exts.dart +++ b/example/lib/exts.dart @@ -136,6 +136,23 @@ extension LKExampleExt on BuildContext { ), ); + Future showRecordingStatusChangedDialog(bool isActiveRecording) => + showDialog( + 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 showSubscribePermissionDialog() => showDialog( context: this, builder: (ctx) => AlertDialog( diff --git a/example/lib/pages/room.dart b/example/lib/pages/room.dart index 93e8d48e..e48a3ea9 100644 --- a/example/lib/pages/room.dart +++ b/example/lib/pages/room.dart @@ -61,6 +61,9 @@ class _RoomPageState extends State { WidgetsBindingCompatible.instance ?.addPostFrameCallback((timeStamp) => Navigator.pop(context)); }) + ..on((event) { + context.showRecordingStatusChangedDialog(event.activeRecording); + }) ..on((_) => _sortParticipants()) ..on((_) => _sortParticipants()) ..on((event) { diff --git a/lib/src/core/room.dart b/lib/src/core/room.dart index ca731c6e..ff67acb6 100644 --- a/lib/src/core/room.dart +++ b/lib/src/core/room.dart @@ -71,6 +71,9 @@ class Room extends DisposableChangeNotifier with EventsEmittable { 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 get activeSpeakers => UnmodifiableListView(_activeSpeakers); @@ -154,6 +157,12 @@ class Room extends DisposableChangeNotifier with EventsEmittable { _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}'); @@ -262,6 +271,11 @@ class Room extends DisposableChangeNotifier with EventsEmittable { _metadata = event.room.metadata; emitWhenConnected( RoomMetadataChangedEvent(metadata: event.room.metadata)); + if (_isRecording != event.room.activeRecording) { + _isRecording = event.room.activeRecording; + emitWhenConnected( + RoomRecordingStatusChanged(activeRecording: _isRecording)); + } }) ..on((event) { // during reconnection, need to send sync state upon signal connection. diff --git a/lib/src/events.dart b/lib/src/events.dart index cf76d87d..39ee71d2 100644 --- a/lib/src/events.dart +++ b/lib/src/events.dart @@ -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].