joinRoom function

Future<ResponseJoinRoom> joinRoom(
  1. JoinRoomOptions options
)

Joins a room on the socket server with specified options.

This function validates the input parameters, then emits a joinRoom event to the server. It returns a Future that completes with the server’s response data or an error if validation fails or if the server returns a specific status.

  • Throws: Exception if input validation fails or if the user is banned, suspended, or if the host has not joined the room yet.

  • Returns: A Future<Map<String, dynamic>> containing the server's response data on success.

Example usage:

final socket = io.io('https://your-socket-server.com', <String, dynamic>{
  'transports': ['websocket'],
  'autoConnect': false,
});
socket.connect();

final options = JoinRoomOptions(
  socket: socket,
  roomName: 's12345678',
  islevel: '1',
  member: 'User123',
  sec: 'your-secure-key-here-64-characters-long',
  apiUserName: 'apiUser',
);

try {
  final response = await joinRoom(options);
  print('Successfully joined room: $response');
} catch (e) {
  print('Error joining room: $e');
}

Parameters:

  • options (JoinRoomOptions): The options for joining the room, including socket and user details.

Implementation

Future<ResponseJoinRoom> joinRoom(JoinRoomOptions options) async {
  // Validate inputs
  if (!_validateInputs(options)) {
    throw Exception('Validation failed for input parameters.');
  }

  // Emit the 'joinRoom' event and return the response
  return await _emitJoinRoom(
    options.socket,
    options.roomName,
    options.islevel,
    options.member,
    options.sec,
    options.apiUserName,
  );
}