exec method

Future<Map<String, dynamic>> exec({
  1. required String name,
  2. required String image,
  3. required String? command,
  4. required String? pullSecret,
  5. String? participantName,
  6. String? role,
  7. Map<String, String>? env,
  8. String? roomStoragePath,
})

Implementation

Future<Map<String, dynamic>> exec({
  required String name,
  required String image,
  required String? command,
  required String? pullSecret,
  String? participantName,
  String? role,
  Map<String, String>? env,
  String? roomStoragePath,
}) async {
  final ws = (protocol.channel as WebSocketProtocolChannel);
  final baseUrl = ws.url.toString();

  final uri = Uri.parse('$baseUrl/exec').replace(scheme: ws.url.scheme.replaceAll("ws", "http"));

  final response = await post(
    uri,
    headers: {"Authorization": "Bearer ${ws.jwt}"},
    body: jsonEncode({
      "image": image,
      "name": name,
      "command": command,
      "pull_secret": pullSecret,
      "env": env,
      "room_storage_path": roomStoragePath,
      "participant_name": participantName,
      "role": role,
    }),
  );

  if (response.statusCode >= 400) {
    throw Exception(
      'Failed to execute. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }

  return jsonDecode(response.body) as Map<String, dynamic>;
}