fetchConnectionDetails method

Future<ConnectionDetails> fetchConnectionDetails({
  1. required String roomName,
  2. required String participantName,
  3. String? botId = "687dc0a17cc36a87d9f11f46",
  4. String? promptId = "6896c13a584b7cfacb0b1adb",
  5. String? userId = "+919526019424",
  6. String language = 'en',
  7. String theme = 'dark',
})

Fetch connection details from your backend

Implementation

Future<ConnectionDetails> fetchConnectionDetails({
  required String roomName,
  required String participantName,
  String? botId = "687dc0a17cc36a87d9f11f46",
  String? promptId ="6896c13a584b7cfacb0b1adb",
  String? userId ="+919526019424",
  String language = 'en',
  String theme = 'dark',
}) async {
  final uri = Uri.parse(tokenEndpoint);

  try {
    final response = await http.post(
      uri,
      headers: {'Content-Type': 'application/json'},
      body: jsonEncode({
        'roomName': roomName,
        'participantName': participantName,
        'botId': botId,
        'promptId': promptId,
        'userId': userId,
        'language': language,
        'theme': theme,
      }),
    );

    if (response.statusCode >= 200 && response.statusCode < 300) {
      final data = jsonDecode(response.body);
      return ConnectionDetails.fromJson(data);
    } else {
      throw Exception(
        'Error from token server: ${response.statusCode}, ${response.body}',
      );
    }
  } catch (e) {
    throw Exception('Failed to connect to token server: $e');
  }
}