joinRoomClient function
- JoinRoomClientOptions options
Joins a room by emitting the joinRoom
or joinConRoom
event to the server using the provided socket.
This function uses JoinRoomClientOptions
as input, selecting joinRoom
if consume
is false
and joinConRoom
if consume
is true. It returns a ResponseJoinRoom
object containing data
from the server. If the process fails, an error is thrown and a message is logged in debug mode.
Example Usage:
final options = JoinRoomClientOptions(
socket: io.Socket(),
roomName: 'meeting123',
islevel: '1',
member: 'user123',
sec: 'abc123',
apiUserName: 'user123',
consume: true,
);
try {
final response = await joinRoomClient(options);
print('Joined room successfully: ${response.roomId}');
} catch (error) {
print('Error joining room: $error');
}
In this example:
- The function attempts to join
meeting123
usingjoinConRoom
(sinceconsume
is true). - If successful, it prints the
roomId
fromResponseJoinRoom
. If not, it catches and logs the error.
Implementation
Future<ResponseJoinRoom> joinRoomClient(JoinRoomClientOptions options) async {
try {
ResponseJoinRoom data;
if (options.consume) {
// Use `joinConRoom` for consuming
final option = JoinConRoomOptions(
socket: options.socket,
roomName: options.roomName,
islevel: options.islevel,
member: options.member,
sec: options.sec,
apiUserName: options.apiUserName,
);
data = await joinConRoom(
option,
);
} else {
// Use `joinRoom` for non-consuming
final option = JoinRoomOptions(
socket: options.socket,
roomName: options.roomName,
islevel: options.islevel,
member: options.member,
sec: options.sec,
apiUserName: options.apiUserName,
);
data = await joinRoom(
option,
);
}
return data;
} catch (error) {
if (kDebugMode) {
print('Error joining room: $error');
}
throw Exception(
'Failed to join the room. Please check your connection and try again.');
}
}