read Engine's connectionState instead of own property

This commit is contained in:
Hiroshi Horie
2022-03-04 19:32:07 +09:00
parent 39fa024a6f
commit d278310748
+8 -15
View File
@@ -27,10 +27,8 @@ import 'engine.dart';
/// * active speakers are different /// * active speakers are different
/// {@category Room} /// {@category Room}
class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> { class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
// Room is only instantiated if connected, so defaults to connected.
/// connection state of the room /// connection state of the room
ConnectionState get connectionState => _connectionState; ConnectionState get connectionState => engine.connectionState;
ConnectionState _connectionState = ConnectionState.connected;
/// map of SID to RemoteParticipant /// map of SID to RemoteParticipant
UnmodifiableMapView<String, RemoteParticipant> get participants => UnmodifiableMapView<String, RemoteParticipant> get participants =>
@@ -119,19 +117,20 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
void _setUpListeners() => _engineListener void _setUpListeners() => _engineListener
..on<EngineConnectedEvent>((event) async { ..on<EngineConnectedEvent>((event) async {
_connectionState = ConnectionState.connected; // _connectionState = ConnectionState.connected;
notifyListeners(); notifyListeners();
}) })
..on<EngineReconnectedEvent>((event) async { ..on<EngineReconnectedEvent>((event) async {
_connectionState = ConnectionState.connected;
events.emit(const RoomReconnectedEvent()); events.emit(const RoomReconnectedEvent());
await _handlePostReconnect(false); await _handlePostReconnect(false);
}) })
..on<EngineReconnectingEvent>((event) async { ..on<EngineReconnectingEvent>((event) async {
_connectionState = ConnectionState.reconnecting;
events.emit(const RoomReconnectingEvent()); events.emit(const RoomReconnectingEvent());
}) })
..on<EngineDisconnectedEvent>((event) => _handleClose()) ..on<EngineDisconnectedEvent>((event) async {
await _handleClose();
events.emit(const RoomDisconnectedEvent());
})
..on<SignalConnectionStateUpdatedEvent>((event) { ..on<SignalConnectionStateUpdatedEvent>((event) {
// during reconnection, need to send sync state upon signal connection. // during reconnection, need to send sync state upon signal connection.
if (event.didReconnect) { if (event.didReconnect) {
@@ -253,7 +252,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
/// Disconnects from the room, notifying server of disconnection. /// Disconnects from the room, notifying server of disconnection.
Future<void> disconnect() async { Future<void> disconnect() async {
if (_connectionState != ConnectionState.disconnected) { if (connectionState != ConnectionState.disconnected) {
engine.signalClient.sendLeave(); engine.signalClient.sendLeave();
} }
await _handleClose(); await _handleClose();
@@ -293,7 +292,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
// there should be no problem calling this method multiple times // there should be no problem calling this method multiple times
Future<void> _handleClose() async { Future<void> _handleClose() async {
logger.fine('[$objectId] _handleClose()'); logger.fine('[$objectId] _handleClose()');
if (_connectionState == ConnectionState.disconnected) { if (connectionState == ConnectionState.disconnected) {
logger.warning('[$objectId]: close() already disconnected'); logger.warning('[$objectId]: close() already disconnected');
} }
@@ -311,12 +310,6 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
await engine.close(); await engine.close();
_activeSpeakers.clear(); _activeSpeakers.clear();
// only notify if was not disconnected
if (_connectionState != ConnectionState.disconnected) {
_connectionState = ConnectionState.disconnected;
events.emit(const RoomDisconnectedEvent());
}
} }
Future<void> _onParticipantUpdateEvent( Future<void> _onParticipantUpdateEvent(