connectRoom method

Future<RoomConnectionInfo> connectRoom({
  1. required String projectId,
  2. required String roomName,
  3. String? client,
})

POST /accounts/projects/{project_id}/rooms/{room_name}/connect Body: {} Returns { "jwt", "room_name", "project_id", "room_url" } on success.

Implementation

Future<RoomConnectionInfo> connectRoom({required String projectId, required String roomName, String? client}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final encodedRoomName = Uri.encodeComponent(roomName);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/rooms/$encodedRoomName/connect');
  final response = await httpClient.post(uri, body: jsonEncode({"client": client}));

  if (response.statusCode >= 400) {
    if (response.statusCode == 404) {
      throw NotFoundException('Room not found');
    }

    throw MeshagentException(
      'Failed to connect room. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }

  return RoomConnectionInfo.fromJson(jsonDecode(response.body));
}