export interface SwPortHandlerOptions { key: string; scope?: string; serviceWorkerUrl?: string; bindPort: (port: MessagePort) => void | Promise; /** * Upper bound, in ms, for `start()`'s wait for the worker to activate, take * control of the page and answer the handshake. `start()` rejects with a * `ServiceWorkerControlError` past it instead of waiting forever. * Default `DEFAULT_SERVICE_WORKER_TIMEOUT` (30 s). */ timeout?: number; /** * If the page is still uncontrolled once the worker is active — after a * hard reload, say — and the worker does not take it over when asked, * reload the page once instead of rejecting. Default `false`. */ reloadIfUncontrolled?: boolean; } interface ChannelInfo { key: string; clientId?: string; port?: MessagePort; } /** * Page-side counterpart: registers a ServiceWorker and sets up a * MessageChannel with it, re-establishing the connection after SW wake-ups. */ export declare class SwPortHandler { readonly options: SwPortHandlerOptions; private _serviceWorkerUrl?; private _serviceWorker?; private _registrationPromise?; private _registration?; private _cleanupRegistrations?; constructor(options: SwPortHandlerOptions); get key(): string; get scope(): string; /** * The scope as a url on the worker's origin. Resolved against the worker's * own url when one is given, not against this module's: a bundle that is * not an ES module (an IIFE, Theia's frontend) has no `import.meta.url`, and * `new URL(scope, undefined)` threw `Invalid URL` there. Only without a * worker url does the module's location decide (its default `sw-worker.js` * sits next to it). */ get rootUrl(): URL; get serviceWorkerUrl(): string; protected _newCommunicationChannel(): Promise<[MessagePort, MessagePort]>; protected _setCommunicationPort(port: MessagePort): Promise; protected _updateCommunicationChannel(): Promise; protected _getRegistrationInfo(): ChannelInfo; /** * Registers the worker and waits until it is activated and controls this * page, then opens the port to it. The page must be controlled, because * only a controlled page's `fetch()` reaches the worker. When the page * loaded uncontrolled (a hard reload does that), the worker is asked to * claim it. Rejects with a `ServiceWorkerControlError` when that fails or * `timeout` passes (`reason` says which step); a later `start()` tries * again. */ start(): Promise; stop(): Promise; } export interface SwPortDispatcherOptions { self: ServiceWorkerGlobalScope; log?: (...args: unknown[]) => void; } /** * ServiceWorker-side counterpart: maintains an index of connected clients keyed by * clientId, persisted in IndexedDB so it can reclaim ports across SW restarts. */ export declare class SwPortDispatcher { readonly self: ServiceWorkerGlobalScope; readonly log: (...args: unknown[]) => void; readonly handlersIndex: Map; /** * Set of keys that were registered at some point on this SW (sticky — * survives client closures + SW wake-ups via IndexedDB). Lets the fetch * handler distinguish "site URL whose owner is gone → 404" from * "unknown URL under scope → pass through to the network". */ readonly claimedKeys: Set; private _cleanup?; private _activationPromise?; constructor({ self, log }: SwPortDispatcherOptions); get scope(): string; /** * Look up the active channel for a key. Returns `undefined` when there * is no registration (or the registering client has gone away — stale * entries are pruned in place). */ loadChannelInfo(key: string): Promise; /** Whether `key` has ever been registered on this SW. */ isClaimedKey(key: string): boolean; start(): void; stop(): Promise; private _checkActivation; private _activate; private _updateChannelInfo; private _loadClientIds; private _updateClientIds; } export {}; //# sourceMappingURL=sw-dispatcher.d.ts.map