diff --git a/lib/src/core/room.dart b/lib/src/core/room.dart index ee1c395..a903f3a 100644 --- a/lib/src/core/room.dart +++ b/lib/src/core/room.dart @@ -27,10 +27,8 @@ import 'engine.dart'; /// * active speakers are different /// {@category Room} class Room extends DisposableChangeNotifier with EventsEmittable { - // Room is only instantiated if connected, so defaults to connected. /// connection state of the room - ConnectionState get connectionState => _connectionState; - ConnectionState _connectionState = ConnectionState.connected; + ConnectionState get connectionState => engine.connectionState; /// map of SID to RemoteParticipant UnmodifiableMapView get participants => @@ -119,19 +117,20 @@ class Room extends DisposableChangeNotifier with EventsEmittable { void _setUpListeners() => _engineListener ..on((event) async { - _connectionState = ConnectionState.connected; + // _connectionState = ConnectionState.connected; notifyListeners(); }) ..on((event) async { - _connectionState = ConnectionState.connected; events.emit(const RoomReconnectedEvent()); await _handlePostReconnect(false); }) ..on((event) async { - _connectionState = ConnectionState.reconnecting; events.emit(const RoomReconnectingEvent()); }) - ..on((event) => _handleClose()) + ..on((event) async { + await _handleClose(); + events.emit(const RoomDisconnectedEvent()); + }) ..on((event) { // during reconnection, need to send sync state upon signal connection. if (event.didReconnect) { @@ -253,7 +252,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable { /// Disconnects from the room, notifying server of disconnection. Future disconnect() async { - if (_connectionState != ConnectionState.disconnected) { + if (connectionState != ConnectionState.disconnected) { engine.signalClient.sendLeave(); } await _handleClose(); @@ -293,7 +292,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable { // there should be no problem calling this method multiple times Future _handleClose() async { logger.fine('[$objectId] _handleClose()'); - if (_connectionState == ConnectionState.disconnected) { + if (connectionState == ConnectionState.disconnected) { logger.warning('[$objectId]: close() already disconnected'); } @@ -311,12 +310,6 @@ class Room extends DisposableChangeNotifier with EventsEmittable { await engine.close(); _activeSpeakers.clear(); - - // only notify if was not disconnected - if (_connectionState != ConnectionState.disconnected) { - _connectionState = ConnectionState.disconnected; - events.emit(const RoomDisconnectedEvent()); - } } Future _onParticipantUpdateEvent(