@supabase/realtime-js
Advanced tools
Comparing version 2.10.4 to 2.10.5-next.1
@@ -1,2 +0,2 @@ | ||
export declare const version = "2.10.4"; | ||
export declare const version = "2.10.5-next.1"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '2.10.4'; | ||
exports.version = '2.10.5-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. | ||
*/ | ||
@@ -96,0 +103,0 @@ constructor(endPoint: string, options?: RealtimeClientOptions); |
@@ -51,2 +51,4 @@ "use strict"; | ||
* @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. | ||
*/ | ||
@@ -136,2 +138,10 @@ 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) || 'https://realtime.supabase.com/worker.js'; | ||
} | ||
} | ||
@@ -362,4 +372,23 @@ /** | ||
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 { | ||
this.log('worker', `starting worker for from ${this.workerUrl}`); | ||
this.workerRef = new Worker(this.workerUrl); | ||
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()); | ||
@@ -366,0 +395,0 @@ } |
@@ -1,2 +0,2 @@ | ||
export declare const version = "2.10.4"; | ||
export declare const version = "2.10.5-next.1"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export const version = '2.10.4'; | ||
export const version = '2.10.5-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. | ||
*/ | ||
@@ -96,0 +103,0 @@ constructor(endPoint: string, options?: RealtimeClientOptions); |
@@ -23,2 +23,4 @@ import { CHANNEL_EVENTS, CONNECTION_STATE, DEFAULT_HEADERS, DEFAULT_TIMEOUT, SOCKET_STATES, TRANSPORTS, VSN, WS_CLOSE_NORMAL, } from './lib/constants'; | ||
* @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. | ||
*/ | ||
@@ -108,2 +110,10 @@ 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) || 'https://realtime.supabase.com/worker.js'; | ||
} | ||
} | ||
@@ -334,4 +344,23 @@ /** | ||
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 { | ||
this.log('worker', `starting worker for from ${this.workerUrl}`); | ||
this.workerRef = new Worker(this.workerUrl); | ||
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()); | ||
@@ -338,0 +367,0 @@ } |
{ | ||
"name": "@supabase/realtime-js", | ||
"version": "2.10.4", | ||
"version": "2.10.5-next.1", | ||
"description": "Listen to realtime updates to your PostgreSQL database", | ||
@@ -26,2 +26,3 @@ "keywords": [ | ||
"license": "MIT", | ||
"type": "module", | ||
"scripts": { | ||
@@ -33,4 +34,5 @@ "clean": "rimraf dist docs/v2", | ||
"build:module": "tsc -p tsconfig.module.json", | ||
"mocha": "node -r esm node_modules/.bin/mocha ./test/**/*.js -r jsdom-global/register", | ||
"test": "run-s clean build mocha", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"coverage": "vitest run --coverage", | ||
"docs": "typedoc src/index.ts --out docs/v2", | ||
@@ -46,2 +48,3 @@ "docs:json": "typedoc --json docs/v2/spec.json --excludeExternals src/index.ts" | ||
"devDependencies": { | ||
"@vitest/coverage-v8": "^2.0.5", | ||
"eslint": "^7.0.0", | ||
@@ -51,3 +54,2 @@ "esm": "^3.2.25", | ||
"jsdom-global": "3.0.0", | ||
"mocha": "^8.0.1", | ||
"mock-socket": "^9.0.3", | ||
@@ -60,4 +62,6 @@ "npm-run-all": "^4.1.5", | ||
"typedoc": "^0.22.16", | ||
"typescript": "^4.0.3" | ||
"typescript": "^4.0.3", | ||
"vitest": "^2.0.5", | ||
"web-worker": "1.2.0" | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
export const version = '2.10.4' | ||
export const version = '2.10.5-next.1' |
@@ -41,2 +41,4 @@ import type { WebSocket as WSWebSocket } from 'ws' | ||
fetch?: Fetch | ||
worker?: boolean | ||
workerUrl?: string | ||
} | ||
@@ -108,2 +110,5 @@ | ||
fetch: Fetch | ||
worker?: boolean | ||
workerUrl?: string | ||
workerRef?: Worker | ||
@@ -124,2 +129,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. | ||
*/ | ||
@@ -166,2 +173,10 @@ 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 || 'https://realtime.supabase.com/worker.js' | ||
} | ||
} | ||
@@ -183,3 +198,2 @@ | ||
} | ||
if (NATIVE_WEBSOCKET_AVAILABLE) { | ||
@@ -461,7 +475,27 @@ this.conn = new WebSocket(this._endPointURL()) | ||
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 { | ||
this.log('worker', `starting worker for from ${this.workerUrl!}`) | ||
this.workerRef = new Worker(this.workerUrl!) | ||
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())! | ||
@@ -468,0 +502,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
377889
6750
Yes
15
1