/** * The messages between pages, Dedicated Workers and the same-origin * ServiceWorker. Internal: the shapes may change between versions, which is * why every hand-shake carries `HTTP_LINK_PROTOCOL`. * * THREE PORTS PER HANDLER LINK. A page makes the channels and hands one end of * each to the handler (itself, or a worker) and the other to the * ServiceWorker; after that it carries nothing: * * - `down`: ServiceWorker → handler, the requests the handler serves; * - `ctl`: a raw port next to them, for what HTTP over a stream cannot carry, * transferred `MessagePort`s (WebSocket hand-over); * - `up` (workers only): handler → ServiceWorker, the requests the handler * sends through the router (to other handlers). */ /** Page → ServiceWorker: attach a handler link. The name is the one version 1 used. */ export declare const ATTACH_CALL = "UPDATE_COMMUNICATION_PORT"; /** Page → ServiceWorker: remove a handler link now. */ export declare const DETACH_CALL = "webrun-http:detach"; /** Page → ServiceWorker: stop routing to a link, let its requests finish, then remove it. */ export declare const DRAIN_CALL = "webrun-http:drain"; /** Page → ServiceWorker: open a WebSocket to a handler. */ export declare const WS_CONNECT_CALL = "webrun-http:ws-connect"; /** ServiceWorker → pages: attach your links again (the ServiceWorker restarted). */ export declare const NEED_LINKS_CALL = "webrun-http:need-links"; /** * Page → ServiceWorker, plain messages (no reply). A message to the * ServiceWorker object is an event: it starts a stopped worker and resets its * idle timer. Port messages do neither. */ export declare const WAKE_MESSAGE = "webrun-http:wake"; export declare const KEEPALIVE_MESSAGE = "webrun-http:keepalive"; export interface AttachParams { /** `HTTP_LINK_PROTOCOL`; absent from version 1 pages. */ wire?: string; key: string; /** The handler slot. Attaching an id that is attached already replaces it. */ id?: string; /** Token of this attachment, named by `drain` / `detach`. */ owner?: string; /** A Web Lock the handler holds while it lives. */ ownerLock?: string; /** Whatever the host wants a `route` function to see. */ meta?: unknown; /** Which ports follow `down` in the transfer list, in this order. */ ctl?: boolean; up?: boolean; } export interface AttachReply { /** `HTTP_LINK_PROTOCOL`: proves the worker speaks it. */ accepted: string; /** The Web Lock the ServiceWorker holds while it lives; absent without Web Locks. */ routerLock?: string; } export interface DrainParams { key: string; id: string; owner: string; /** How long requests in flight may run before the link is closed anyway. */ ms?: number; } export interface NeedLinksParams { /** Links made for this router are alive; only the others need attaching again. */ routerLock?: string; } /** The `ctl` port's messages. */ export type ControlMessage = { t: "ws-connect"; id: string; url: string; protocols: string[]; headers?: [string, string][]; } | { t: "ws-accept"; id: string; protocol: string; port: MessagePort; } | { t: "ws-refuse"; id: string; status: number; message: string; } | { t: "ws-open"; id: string; url: string; protocols: string[]; } | { t: "ws-opened"; id: string; protocol: string; port: MessagePort; } | { t: "ws-failed"; id: string; message: string; }; /** Page ↔ worker: what `attachWorker` and `serveHttpInWorker` exchange. */ export declare const WORKER_HELLO = "webrun-http:worker-hello"; export type WorkerControlMessage = { type: "ready"; ownerLock?: string; } | { type: "link"; key: string; routerLock?: string; } | { type: "unlink"; key: string; } | { type: "relink"; } | { type: "keepalive"; }; //# sourceMappingURL=protocol.d.ts.map