connect method

Room connect()

Connects to the room and returns the instance of the room @throws { Error } If the socket connection is not connected, or if the socket connection is connecting

Implementation

Room connect() {
  logger.i("🚪 Room | Connect");
  if (!_socket.connected) {
    throw Exception('Socket is Not Connected');
  }

  if (_socket.connecting) {
    throw Exception('Socket is Connecting, Wait for it to be connected');
  }

  if (_roomId == null) {
    throw Exception('Room Id is required to connect to the room');
  }
  logger.i('🔔 Connecting to the room');

  _socket.publish(Request_Request.connectRoom, {'roomId': _roomId});

  state = RoomStates.connecting;
  emit('room-connecting');
  return Room._instance;
}