supabase / supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
https://supabase.com/
MIT License
656 stars 154 forks source link

feat: Allow setting `timeout` of `RealtimeClient`. #932

Closed nns52k closed 1 month ago

nns52k commented 1 month ago

What kind of change does this PR introduce?

Allow the ctor SupabaseClient to set timeout to a RealtimeClient.

What is the current behavior?

Due to the fact the timeout is a final field in RealtimeClient, we cannot change its value after the RealtimeClient is created, and because the RealtimeClient is created in the ctor of SupabaseClient, there is no way for users to set the timeout.

What is the new behavior?

The new behavior allow us to set the timeout of the RealtimeClient like this:

final SupabaseClient supabase = SupabaseClient(
  'https://your.supabase.address/',
  'your_anon_key',
  realtimeClientOptions: RealtimeClientOptions(timeout: Duration(minutes: 1)),
);

Additional context

My app is connecting Supabase through Tor proxy. It's normal to cost 10 or more seconds to build a WebSocket connection. However, the current default timeout of RealtimeClient is 10 seconds, which is too short, and very often leads to result of no WebSocket connection is created, and therefore no realtime feature is provided.