Skip to content

Commit 2ffa2d9

Browse files
authored
feat: pass along realtime-js options (#216)
* Pass along realtime-js options * Update src/lib/types.ts * Feedback adjustment * Bump realtime-js * Adjust for upstream changes
1 parent 0d9d8fb commit 2ffa2d9

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"dependencies": {
3939
"@supabase/gotrue-js": "^1.16.6",
4040
"@supabase/postgrest-js": "^0.33.0",
41-
"@supabase/realtime-js": "^1.0.11",
41+
"@supabase/realtime-js": "^1.1.1",
4242
"@supabase/storage-js": "^1.2.2"
4343
},
4444
"devDependencies": {

src/SupabaseClient.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
44
import { SupabaseQueryBuilder } from './lib/SupabaseQueryBuilder'
55
import { SupabaseStorageClient } from '@supabase/storage-js'
66
import { PostgrestClient } from '@supabase/postgrest-js'
7-
import { RealtimeClient, RealtimeSubscription } from '@supabase/realtime-js'
7+
import { RealtimeClient, RealtimeSubscription, RealtimeClientOptions } from '@supabase/realtime-js'
88

99
const DEFAULT_OPTIONS = {
1010
schema: 'public',
@@ -42,6 +42,7 @@ export default class SupabaseClient {
4242
* @param options.persistSession Set to "true" if you want to automatically save the user session into local storage.
4343
* @param options.detectSessionInUrl Set to "true" if you want to automatically detects OAuth grants in the URL and signs in the user.
4444
* @param options.headers Any additional headers to send with each network request.
45+
* @param options.realtime Options passed along to realtime-js constructor.
4546
*/
4647
constructor(
4748
protected supabaseUrl: string,
@@ -59,7 +60,7 @@ export default class SupabaseClient {
5960
this.schema = settings.schema
6061

6162
this.auth = this._initSupabaseAuthClient(settings)
62-
this.realtime = this._initRealtimeClient()
63+
this.realtime = this._initRealtimeClient(settings.realtime)
6364

6465
// In the future we might allow the user to pass in a logger to receive these events.
6566
// this.realtime.onOpen(() => console.log('OPEN'))
@@ -154,9 +155,10 @@ export default class SupabaseClient {
154155
})
155156
}
156157

157-
private _initRealtimeClient() {
158+
private _initRealtimeClient(options?: RealtimeClientOptions) {
158159
return new RealtimeClient(this.realtimeUrl, {
159-
params: { apikey: this.supabaseKey },
160+
...options,
161+
params: { ...options?.params, apikey: this.supabaseKey },
160162
})
161163
}
162164

src/lib/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { RealtimeClientOptions } from '@supabase/realtime-js'
2+
13
export type SupabaseClientOptions = {
24
/**
35
* The Postgres schema which your tables belong to. Must be on the list of exposed schemas in Supabase. Defaults to 'public'.
@@ -23,6 +25,11 @@ export type SupabaseClientOptions = {
2325
* A storage provider. Used to store the logged in session.
2426
*/
2527
localStorage?: Storage
28+
29+
/**
30+
* Options passed to the realtime-js instance
31+
*/
32+
realtime?: RealtimeClientOptions
2633
}
2734

2835
export type SupabaseRealtimePayload<T> = {

0 commit comments

Comments
 (0)