listHosts method
List available hosts on the relay.
Implementation
Future<List<Map<String, dynamic>>> listHosts() async {
final client = HttpClient();
try {
final uri = Uri.parse(relayUrl.replaceFirst('ws', 'http'));
final request = await client.getUrl(uri.replace(path: '/api/hosts'));
if (relayToken != null) {
request.headers.set('Authorization', 'Bearer $relayToken');
}
final response = await request.close();
final body = await response.transform(utf8.decoder).join();
return (jsonDecode(body) as List<dynamic>).cast<Map<String, dynamic>>();
} finally {
client.close();
}
}