EngineConnectionStateUpdatedEvent instead of individual events
This commit is contained in:
+37
-37
@@ -116,21 +116,19 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
}
|
||||
|
||||
void _setUpListeners() => _engineListener
|
||||
..on<EngineConnectedEvent>((event) async {
|
||||
// _connectionState = ConnectionState.connected;
|
||||
..on<EngineConnectionStateUpdatedEvent>((event) async {
|
||||
if (event.didReconnect) {
|
||||
events.emit(const RoomReconnectedEvent());
|
||||
await _handlePostReconnect(false);
|
||||
} else if (event.newState == ConnectionState.reconnecting) {
|
||||
events.emit(const RoomReconnectingEvent());
|
||||
} else if (event.newState == ConnectionState.disconnected) {
|
||||
await _cleanUp();
|
||||
events.emit(const RoomDisconnectedEvent());
|
||||
}
|
||||
// always notify ChangeNotifier
|
||||
notifyListeners();
|
||||
})
|
||||
..on<EngineReconnectedEvent>((event) async {
|
||||
events.emit(const RoomReconnectedEvent());
|
||||
await _handlePostReconnect(false);
|
||||
})
|
||||
..on<EngineReconnectingEvent>((event) async {
|
||||
events.emit(const RoomReconnectingEvent());
|
||||
})
|
||||
..on<EngineDisconnectedEvent>((event) async {
|
||||
await _handleClose();
|
||||
events.emit(const RoomDisconnectedEvent());
|
||||
})
|
||||
..on<SignalConnectionStateUpdatedEvent>((event) {
|
||||
// during reconnection, need to send sync state upon signal connection.
|
||||
if (event.didReconnect) {
|
||||
@@ -255,7 +253,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
if (connectionState != ConnectionState.disconnected) {
|
||||
engine.signalClient.sendLeave();
|
||||
}
|
||||
await _handleClose();
|
||||
await _cleanUp();
|
||||
}
|
||||
|
||||
Future<void> reconnect() async {
|
||||
@@ -289,29 +287,6 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
return participant;
|
||||
}
|
||||
|
||||
// there should be no problem calling this method multiple times
|
||||
Future<void> _handleClose() async {
|
||||
logger.fine('[$objectId] _handleClose()');
|
||||
if (connectionState == ConnectionState.disconnected) {
|
||||
logger.warning('[$objectId]: close() already disconnected');
|
||||
}
|
||||
|
||||
// clean up RemoteParticipants
|
||||
for (final _ in _participants.values.toList()) {
|
||||
// RemoteParticipant is responsible for disposing resources
|
||||
await _.dispose();
|
||||
}
|
||||
_participants.clear();
|
||||
|
||||
// clean up LocalParticipant
|
||||
await localParticipant?.unpublishAllTracks();
|
||||
|
||||
// clean up engine
|
||||
await engine.close();
|
||||
|
||||
_activeSpeakers.clear();
|
||||
}
|
||||
|
||||
Future<void> _onParticipantUpdateEvent(
|
||||
List<lk_models.ParticipantInfo> updates) async {
|
||||
// trigger change notifier only if list of participants membership is changed
|
||||
@@ -510,3 +485,28 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension RoomPrivateMethods on Room {
|
||||
// resets internal state to a re-usable state
|
||||
Future<void> _cleanUp() async {
|
||||
logger.fine('[$objectId] _handleClose()');
|
||||
if (connectionState == ConnectionState.disconnected) {
|
||||
logger.warning('[$objectId]: close() already disconnected');
|
||||
}
|
||||
|
||||
// clean up RemoteParticipants
|
||||
for (final _ in _participants.values.toList()) {
|
||||
// RemoteParticipant is responsible for disposing resources
|
||||
await _.dispose();
|
||||
}
|
||||
_participants.clear();
|
||||
|
||||
// clean up LocalParticipant
|
||||
await localParticipant?.unpublishAllTracks();
|
||||
|
||||
// clean up engine
|
||||
await engine.close();
|
||||
|
||||
_activeSpeakers.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user