Closed nns52k closed 1 month ago
There is no way to pass a HttpClient
to WebSocketChannel
like what we can do to SupabaseClient
, but defining HttpOverrides.createHttpClient
and running all Supabase code in a HttpOverrides.runZoned
is a workaround.
Describe the bug
Unable to create a WebSocket connection to access Realtime on an .onion server.
To Reproduce
void main(List arguments) async {
HttpClient httpClient = await connectTorProxy(9050);
final supabase = SupabaseClient(
'http://your_onion_address.onion',
'your_anon_key',
httpClient: IOClient(httpClient),
);
await listenToATable(supabase);
}
Future connectTorProxy(int portNumber) async {
final httpClient = HttpClient();
SocksTCPClient.assignToHttpClient(httpClient, [
ProxySettings(InternetAddress.loopbackIPv4, portNumber),
]);
return httpClient;
}
Future listenToATable(SupabaseClient supabase) async {
final SupabaseQueryBuilder queryBuilder = supabase.from('countries'); // Assume we have SQL table
countries
. final SupabaseStreamFilterBuilder streamFilterBuilder = queryBuilder.stream(primaryKey: ['id']); streamFilterBuilder.listen((List<Map<String, dynamic>> resultSet) { print(supabase.realtime.isConnected); printResultSet(resultSet); }); } void printResultSet(List<Map<String, dynamic>> resultSet, {bool hasRowSeparator = true}) { for (Map<String, dynamic> row in resultSet) { row.forEach((String columnName, dynamic columnValue) { print('$columnName: $columnValue'); }); if (hasRowSeparator) print('----------'); } }├── supabase 2.1.2 │ ├── functions_client 2.1.0 │ ├── gotrue 2.6.1 │ ├── postgrest 2.1.1 │ ├── realtime_client 2.0.4 │ ├── storage_client 2.0.1
The callstack of the DNS lookup that causes the exception is as follows: