@supabase/realtime-js 2.7.4 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/RealtimeChannel.d.ts +6 -1
- package/dist/main/RealtimeChannel.d.ts.map +1 -1
- package/dist/main/RealtimeChannel.js +77 -36
- package/dist/main/RealtimeChannel.js.map +1 -1
- package/dist/main/RealtimeClient.d.ts +4 -0
- package/dist/main/RealtimeClient.d.ts.map +1 -1
- package/dist/main/RealtimeClient.js +53 -27
- package/dist/main/RealtimeClient.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/module/RealtimeChannel.d.ts +6 -1
- package/dist/module/RealtimeChannel.d.ts.map +1 -1
- package/dist/module/RealtimeChannel.js +77 -36
- package/dist/module/RealtimeChannel.js.map +1 -1
- package/dist/module/RealtimeClient.d.ts +4 -0
- package/dist/module/RealtimeClient.d.ts.map +1 -1
- package/dist/module/RealtimeClient.js +31 -28
- package/dist/module/RealtimeClient.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/package.json +2 -1
- package/src/RealtimeChannel.ts +95 -19
- package/src/RealtimeClient.ts +26 -4
- package/src/lib/version.ts +1 -1
package/src/RealtimeClient.ts
CHANGED
|
@@ -14,6 +14,8 @@ import Serializer from './lib/serializer'
|
|
|
14
14
|
import RealtimeChannel from './RealtimeChannel'
|
|
15
15
|
import type { RealtimeChannelOptions } from './RealtimeChannel'
|
|
16
16
|
|
|
17
|
+
type Fetch = typeof fetch
|
|
18
|
+
|
|
17
19
|
export type RealtimeClientOptions = {
|
|
18
20
|
transport?: WebSocket
|
|
19
21
|
timeout?: number
|
|
@@ -25,6 +27,7 @@ export type RealtimeClientOptions = {
|
|
|
25
27
|
headers?: { [key: string]: string }
|
|
26
28
|
params?: { [key: string]: any }
|
|
27
29
|
log_level?: 'info' | 'debug' | 'warn' | 'error'
|
|
30
|
+
fetch?: Fetch
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
export type RealtimeMessage = {
|
|
@@ -72,6 +75,7 @@ export default class RealtimeClient {
|
|
|
72
75
|
}
|
|
73
76
|
eventsPerSecondLimitMs: number = 100
|
|
74
77
|
inThrottle: boolean = false
|
|
78
|
+
fetch: Fetch
|
|
75
79
|
|
|
76
80
|
/**
|
|
77
81
|
* Initializes the Socket.
|
|
@@ -122,6 +126,8 @@ export default class RealtimeClient {
|
|
|
122
126
|
this.disconnect()
|
|
123
127
|
this.connect()
|
|
124
128
|
}, this.reconnectAfterMs)
|
|
129
|
+
|
|
130
|
+
this.fetch = this._resolveFetch(options?.fetch)
|
|
125
131
|
}
|
|
126
132
|
|
|
127
133
|
/**
|
|
@@ -232,10 +238,6 @@ export default class RealtimeClient {
|
|
|
232
238
|
topic: string,
|
|
233
239
|
params: RealtimeChannelOptions = { config: {} }
|
|
234
240
|
): RealtimeChannel {
|
|
235
|
-
if (!this.isConnected()) {
|
|
236
|
-
this.connect()
|
|
237
|
-
}
|
|
238
|
-
|
|
239
241
|
const chan = new RealtimeChannel(`realtime:${topic}`, params, this)
|
|
240
242
|
this.channels.push(chan)
|
|
241
243
|
return chan
|
|
@@ -285,6 +287,26 @@ export default class RealtimeClient {
|
|
|
285
287
|
})
|
|
286
288
|
}
|
|
287
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Use either custom fetch, if provided, or default fetch to make HTTP requests
|
|
292
|
+
*
|
|
293
|
+
* @internal
|
|
294
|
+
*/
|
|
295
|
+
_resolveFetch = (customFetch?: Fetch): Fetch => {
|
|
296
|
+
let _fetch: Fetch
|
|
297
|
+
if (customFetch) {
|
|
298
|
+
_fetch = customFetch
|
|
299
|
+
} else if (typeof fetch === 'undefined') {
|
|
300
|
+
_fetch = (...args) =>
|
|
301
|
+
import('@supabase/node-fetch' as any).then(({ default: fetch }) =>
|
|
302
|
+
fetch(...args)
|
|
303
|
+
)
|
|
304
|
+
} else {
|
|
305
|
+
_fetch = fetch
|
|
306
|
+
}
|
|
307
|
+
return (...args) => _fetch(...args)
|
|
308
|
+
}
|
|
309
|
+
|
|
288
310
|
/**
|
|
289
311
|
* Return the next message ref, accounting for overflows
|
|
290
312
|
*
|
package/src/lib/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.8.0'
|