fetchConnectionDetails method
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');
}
}