disconnect method

  1. @override
Future<void> disconnect()
override

Closes the real-time connection without clearing state.

Cached rooms/messages and the event stream stay alive — use this when the app goes to background and you want to release the socket but keep the UI hydrated. Pair with connect when the app returns to foreground. Idempotent: safe to call when already disconnected.

Implementation

@override
Future<void> disconnect() async {
  _connectionState = ChatConnectionState.disconnected;
  _stateController.add(_connectionState);
  _eventController.add(const ChatEvent.disconnected());
}