UNPKG

worker-websocket-ctrl

Version:

Share a websocket using a Worker/SharedWorker communicating through comlink

31 lines (30 loc) 1.06 kB
import * as Comlink from 'comlink'; export interface WorkerWsCtrlOptions { keepaliveInterval?: number; keepaliveTimeout?: number; reconnectDelay?: number; closeDelay?: number; } export declare class WorkerWsController { private workerCtx; path: string; private options; private apiUrl; private apiUrlToJoin; private reconnectRef; private closeRef; private keepAliveInterval; private keepAliveTimeout; private reconnectDelay; private closeDelay; constructor(workerCtx: Window, path: string, options?: WorkerWsCtrlOptions); start(apiUrl: string, getProtocols?: (path: string) => Promise<string[] | null>): void; subscribe(onEvent: (ev: string) => void, ping: (pong: () => void) => void, onConnect: () => void, onDisconnect: () => void, onClose: () => void): (() => void) & Comlink.ProxyMarked; sendMessage(data: string): void; private startWs; private startReconnect; private stopReconnect; private keepAlive; private checkSubscriptions; private openSocket; }