Room constructor

Room(
  1. {ConnectOptions connectOptions = const ConnectOptions(),
  2. RoomOptions roomOptions = const RoomOptions(),
  3. Engine? engine}
)

Implementation

Room({
  ConnectOptions connectOptions = const ConnectOptions(),
  RoomOptions roomOptions = const RoomOptions(),
  Engine? engine,
}) : engine = engine ??
          Engine(
            connectOptions: connectOptions,
            roomOptions: roomOptions,
          ) {
  //
  _engineListener = this.engine.createListener();
  _setUpEngineListeners();

  if (!kIsWeb && !lkPlatformIsTest()) {
    _appCloseSubscription =
        AppStateListener.instance.onWindowShouldClose.stream.listen((event) {
      disconnect();
    });
  }

  _signalListener = this.engine.signalClient.createListener();
  _setUpSignalListeners();

  // Any event emitted will trigger ChangeNotifier
  events.listen((event) {
    logger.fine('[RoomEvent] $event, will notifyListeners()');
    notifyListeners();
  });

  onDispose(() async {
    // clean up routine
    await _cleanUp();
    // dispose events
    await events.dispose();
    // dispose local participant
    await localParticipant?.dispose();
    // dispose all listeners for SignalClient
    await _signalListener.dispose();
    // dispose all listeners for Engine
    await _engineListener.dispose();
    // dispose the engine
    await this.engine.dispose();
    // dispose the app state listener
    await _appCloseSubscription?.cancel();
  });
}