@supabase/realtime-js
Advanced tools
Comparing version 2.10.6 to 2.10.7-next.1
@@ -1,2 +0,2 @@ | ||
export declare const version = "2.10.6"; | ||
export declare const version = "2.10.7-next.1"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '2.10.6'; | ||
exports.version = '2.10.7-next.1'; | ||
//# sourceMappingURL=version.js.map |
@@ -30,2 +30,4 @@ import type { WebSocket as WSWebSocket } from 'ws'; | ||
fetch?: Fetch; | ||
worker?: boolean; | ||
workerUrl?: string; | ||
}; | ||
@@ -79,2 +81,5 @@ export declare type RealtimeMessage = { | ||
fetch: Fetch; | ||
worker?: boolean; | ||
workerUrl?: string; | ||
workerRef?: Worker; | ||
/** | ||
@@ -94,2 +99,4 @@ * Initializes the Socket. | ||
* @param options.reconnectAfterMs he optional function that returns the millsec reconnect interval. Defaults to stepped backoff off. | ||
* @param options.worker Use Web Worker to set a side flow. Defaults to false. | ||
* @param options.workerUrl The URL of the worker script. Defaults to https://realtime.supabase.com/worker.js that includes a heartbeat event call to keep the connection alive. | ||
*/ | ||
@@ -148,2 +155,3 @@ constructor(endPoint: string, options?: RealtimeClientOptions); | ||
setAuth(token: string | null): void; | ||
private _workerObjectUrl; | ||
} | ||
@@ -150,0 +158,0 @@ declare class WSWebSocketDummy { |
@@ -36,2 +36,8 @@ "use strict"; | ||
const NATIVE_WEBSOCKET_AVAILABLE = typeof WebSocket !== 'undefined'; | ||
const WORKER_SCRIPT = ` | ||
addEventListener("message", (e) => { | ||
if (e.data.event === "start") { | ||
setInterval(() => postMessage({ event: "keepAlive" }), e.data.interval); | ||
} | ||
});`; | ||
class RealtimeClient { | ||
@@ -52,2 +58,4 @@ /** | ||
* @param options.reconnectAfterMs he optional function that returns the millsec reconnect interval. Defaults to stepped backoff off. | ||
* @param options.worker Use Web Worker to set a side flow. Defaults to false. | ||
* @param options.workerUrl The URL of the worker script. Defaults to https://realtime.supabase.com/worker.js that includes a heartbeat event call to keep the connection alive. | ||
*/ | ||
@@ -137,2 +145,9 @@ constructor(endPoint, options) { | ||
this.fetch = this._resolveFetch(options === null || options === void 0 ? void 0 : options.fetch); | ||
if (options === null || options === void 0 ? void 0 : options.worker) { | ||
if (typeof window !== 'undefined' && !window.Worker) { | ||
throw new Error('Web Worker is not supported'); | ||
} | ||
this.worker = (options === null || options === void 0 ? void 0 : options.worker) || false; | ||
this.workerUrl = options === null || options === void 0 ? void 0 : options.workerUrl; | ||
} | ||
} | ||
@@ -359,8 +374,33 @@ /** | ||
/** @internal */ | ||
_onConnOpen() { | ||
async _onConnOpen() { | ||
this.log('transport', `connected to ${this._endPointURL()}`); | ||
this._flushSendBuffer(); | ||
this.reconnectTimer.reset(); | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer); | ||
this.heartbeatTimer = setInterval(() => this._sendHeartbeat(), this.heartbeatIntervalMs); | ||
if (!this.worker) { | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer); | ||
this.heartbeatTimer = setInterval(() => this._sendHeartbeat(), this.heartbeatIntervalMs); | ||
} | ||
else { | ||
if (this.workerUrl) { | ||
this.log('worker', `starting worker for from ${this.workerUrl}`); | ||
} | ||
else { | ||
this.log('worker', `starting default worker`); | ||
} | ||
const objectUrl = this._workerObjectUrl(this.workerUrl); | ||
this.workerRef = new Worker(objectUrl); | ||
this.workerRef.onerror = (error) => { | ||
this.log('worker', 'worker error', error.message); | ||
this.workerRef.terminate(); | ||
}; | ||
this.workerRef.onmessage = (event) => { | ||
if (event.data.event === 'keepAlive') { | ||
this._sendHeartbeat(); | ||
} | ||
}; | ||
this.workerRef.postMessage({ | ||
event: 'start', | ||
interval: this.heartbeatIntervalMs, | ||
}); | ||
} | ||
this.stateChangeCallbacks.open.forEach((callback) => callback()); | ||
@@ -423,2 +463,13 @@ } | ||
} | ||
_workerObjectUrl(url) { | ||
let result_url; | ||
if (url) { | ||
result_url = url; | ||
} | ||
else { | ||
const blob = new Blob([WORKER_SCRIPT], { type: 'application/javascript' }); | ||
result_url = URL.createObjectURL(blob); | ||
} | ||
return result_url; | ||
} | ||
} | ||
@@ -425,0 +476,0 @@ exports.default = RealtimeClient; |
@@ -1,2 +0,2 @@ | ||
export declare const version = "2.10.6"; | ||
export declare const version = "2.10.7-next.1"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export const version = '2.10.6'; | ||
export const version = '2.10.7-next.1'; | ||
//# sourceMappingURL=version.js.map |
@@ -30,2 +30,4 @@ import type { WebSocket as WSWebSocket } from 'ws'; | ||
fetch?: Fetch; | ||
worker?: boolean; | ||
workerUrl?: string; | ||
}; | ||
@@ -79,2 +81,5 @@ export declare type RealtimeMessage = { | ||
fetch: Fetch; | ||
worker?: boolean; | ||
workerUrl?: string; | ||
workerRef?: Worker; | ||
/** | ||
@@ -94,2 +99,4 @@ * Initializes the Socket. | ||
* @param options.reconnectAfterMs he optional function that returns the millsec reconnect interval. Defaults to stepped backoff off. | ||
* @param options.worker Use Web Worker to set a side flow. Defaults to false. | ||
* @param options.workerUrl The URL of the worker script. Defaults to https://realtime.supabase.com/worker.js that includes a heartbeat event call to keep the connection alive. | ||
*/ | ||
@@ -148,2 +155,3 @@ constructor(endPoint: string, options?: RealtimeClientOptions); | ||
setAuth(token: string | null): void; | ||
private _workerObjectUrl; | ||
} | ||
@@ -150,0 +158,0 @@ declare class WSWebSocketDummy { |
@@ -8,2 +8,8 @@ import { CHANNEL_EVENTS, CONNECTION_STATE, DEFAULT_HEADERS, DEFAULT_TIMEOUT, SOCKET_STATES, TRANSPORTS, VSN, WS_CLOSE_NORMAL, } from './lib/constants'; | ||
const NATIVE_WEBSOCKET_AVAILABLE = typeof WebSocket !== 'undefined'; | ||
const WORKER_SCRIPT = ` | ||
addEventListener("message", (e) => { | ||
if (e.data.event === "start") { | ||
setInterval(() => postMessage({ event: "keepAlive" }), e.data.interval); | ||
} | ||
});`; | ||
export default class RealtimeClient { | ||
@@ -24,2 +30,4 @@ /** | ||
* @param options.reconnectAfterMs he optional function that returns the millsec reconnect interval. Defaults to stepped backoff off. | ||
* @param options.worker Use Web Worker to set a side flow. Defaults to false. | ||
* @param options.workerUrl The URL of the worker script. Defaults to https://realtime.supabase.com/worker.js that includes a heartbeat event call to keep the connection alive. | ||
*/ | ||
@@ -109,2 +117,9 @@ constructor(endPoint, options) { | ||
this.fetch = this._resolveFetch(options === null || options === void 0 ? void 0 : options.fetch); | ||
if (options === null || options === void 0 ? void 0 : options.worker) { | ||
if (typeof window !== 'undefined' && !window.Worker) { | ||
throw new Error('Web Worker is not supported'); | ||
} | ||
this.worker = (options === null || options === void 0 ? void 0 : options.worker) || false; | ||
this.workerUrl = options === null || options === void 0 ? void 0 : options.workerUrl; | ||
} | ||
} | ||
@@ -331,8 +346,33 @@ /** | ||
/** @internal */ | ||
_onConnOpen() { | ||
async _onConnOpen() { | ||
this.log('transport', `connected to ${this._endPointURL()}`); | ||
this._flushSendBuffer(); | ||
this.reconnectTimer.reset(); | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer); | ||
this.heartbeatTimer = setInterval(() => this._sendHeartbeat(), this.heartbeatIntervalMs); | ||
if (!this.worker) { | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer); | ||
this.heartbeatTimer = setInterval(() => this._sendHeartbeat(), this.heartbeatIntervalMs); | ||
} | ||
else { | ||
if (this.workerUrl) { | ||
this.log('worker', `starting worker for from ${this.workerUrl}`); | ||
} | ||
else { | ||
this.log('worker', `starting default worker`); | ||
} | ||
const objectUrl = this._workerObjectUrl(this.workerUrl); | ||
this.workerRef = new Worker(objectUrl); | ||
this.workerRef.onerror = (error) => { | ||
this.log('worker', 'worker error', error.message); | ||
this.workerRef.terminate(); | ||
}; | ||
this.workerRef.onmessage = (event) => { | ||
if (event.data.event === 'keepAlive') { | ||
this._sendHeartbeat(); | ||
} | ||
}; | ||
this.workerRef.postMessage({ | ||
event: 'start', | ||
interval: this.heartbeatIntervalMs, | ||
}); | ||
} | ||
this.stateChangeCallbacks.open.forEach((callback) => callback()); | ||
@@ -395,2 +435,13 @@ } | ||
} | ||
_workerObjectUrl(url) { | ||
let result_url; | ||
if (url) { | ||
result_url = url; | ||
} | ||
else { | ||
const blob = new Blob([WORKER_SCRIPT], { type: 'application/javascript' }); | ||
result_url = URL.createObjectURL(blob); | ||
} | ||
return result_url; | ||
} | ||
} | ||
@@ -397,0 +448,0 @@ class WSWebSocketDummy { |
{ | ||
"name": "@supabase/realtime-js", | ||
"version": "2.10.6", | ||
"version": "2.10.7-next.1", | ||
"description": "Listen to realtime updates to your PostgreSQL database", | ||
@@ -62,4 +62,5 @@ "keywords": [ | ||
"typescript": "^4.0.3", | ||
"vitest": "^2.0.5" | ||
"vitest": "^2.0.5", | ||
"web-worker": "1.2.0" | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
export const version = '2.10.6' | ||
export const version = '2.10.7-next.1' |
@@ -41,2 +41,4 @@ import type { WebSocket as WSWebSocket } from 'ws' | ||
fetch?: Fetch | ||
worker?: boolean | ||
workerUrl?: string | ||
} | ||
@@ -73,3 +75,8 @@ | ||
const NATIVE_WEBSOCKET_AVAILABLE = typeof WebSocket !== 'undefined' | ||
const WORKER_SCRIPT = ` | ||
addEventListener("message", (e) => { | ||
if (e.data.event === "start") { | ||
setInterval(() => postMessage({ event: "keepAlive" }), e.data.interval); | ||
} | ||
});` | ||
export default class RealtimeClient { | ||
@@ -109,2 +116,5 @@ accessToken: string | null = null | ||
fetch: Fetch | ||
worker?: boolean | ||
workerUrl?: string | ||
workerRef?: Worker | ||
@@ -125,2 +135,4 @@ /** | ||
* @param options.reconnectAfterMs he optional function that returns the millsec reconnect interval. Defaults to stepped backoff off. | ||
* @param options.worker Use Web Worker to set a side flow. Defaults to false. | ||
* @param options.workerUrl The URL of the worker script. Defaults to https://realtime.supabase.com/worker.js that includes a heartbeat event call to keep the connection alive. | ||
*/ | ||
@@ -167,2 +179,9 @@ constructor(endPoint: string, options?: RealtimeClientOptions) { | ||
this.fetch = this._resolveFetch(options?.fetch) | ||
if (options?.worker) { | ||
if (typeof window !== 'undefined' && !window.Worker) { | ||
throw new Error('Web Worker is not supported') | ||
} | ||
this.worker = options?.worker || false | ||
this.workerUrl = options?.workerUrl | ||
} | ||
} | ||
@@ -456,11 +475,36 @@ | ||
/** @internal */ | ||
private _onConnOpen() { | ||
private async _onConnOpen() { | ||
this.log('transport', `connected to ${this._endPointURL()}`) | ||
this._flushSendBuffer() | ||
this.reconnectTimer.reset() | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer) | ||
this.heartbeatTimer = setInterval( | ||
() => this._sendHeartbeat(), | ||
this.heartbeatIntervalMs | ||
) | ||
if (!this.worker) { | ||
this.heartbeatTimer && clearInterval(this.heartbeatTimer) | ||
this.heartbeatTimer = setInterval( | ||
() => this._sendHeartbeat(), | ||
this.heartbeatIntervalMs | ||
) | ||
} else { | ||
if (this.workerUrl) { | ||
this.log('worker', `starting worker for from ${this.workerUrl}`) | ||
} else { | ||
this.log('worker', `starting default worker`) | ||
} | ||
const objectUrl = this._workerObjectUrl(this.workerUrl!) | ||
this.workerRef = new Worker(objectUrl) | ||
this.workerRef.onerror = (error) => { | ||
this.log('worker', 'worker error', error.message) | ||
this.workerRef!.terminate() | ||
} | ||
this.workerRef.onmessage = (event) => { | ||
if (event.data.event === 'keepAlive') { | ||
this._sendHeartbeat() | ||
} | ||
} | ||
this.workerRef.postMessage({ | ||
event: 'start', | ||
interval: this.heartbeatIntervalMs, | ||
}) | ||
} | ||
this.stateChangeCallbacks.open.forEach((callback) => callback())! | ||
@@ -470,2 +514,3 @@ } | ||
/** @internal */ | ||
private _onConnClose(event: any) { | ||
@@ -537,2 +582,13 @@ this.log('transport', 'close', event) | ||
} | ||
private _workerObjectUrl(url: string | undefined): string { | ||
let result_url: string | ||
if (url) { | ||
result_url = url | ||
} else { | ||
const blob = new Blob([WORKER_SCRIPT], { type: 'application/javascript' }) | ||
result_url = URL.createObjectURL(blob) | ||
} | ||
return result_url | ||
} | ||
} | ||
@@ -539,0 +595,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
381771
6817
17
1