Skip to content

Backend → Web Push

The wire protocol routes web → backend requests and writes replies. For live updates (a photos.changed event, sync progress), the worklet pushes a server-initiated dispatch to the connected web layer.

createLoopbackPush(server, protocol) builds the push seam from the runtime’s loopback server and protocol codec. createWorkletRuntime already exposes both (runtime.server, runtime.protocol):

import { createLoopbackPush, type WorkletRuntime } from '@ekrooh/bare/runtime';
declare const runtime: WorkletRuntime;
const push = createLoopbackPush(runtime.server, runtime.protocol);
push(
{ type: 'DISPATCH', pluginId: 'app.photos', event: 'photos.changed' },
null,
);

The first argument is a MessageHeader (a DISPATCH envelope, or anything MessageProtocol.encode accepts); the second is an optional payload. push returns false when no socket is connected.

The web layer receives it as any other envelope through transport.subscribe — no transport change needed.

LoopbackServer.push(frame) writes a raw encoded frame to the connected protocol socket — the low-level seam createLoopbackPush wraps.

The push is a broadcast to the single connected client (the loopback server enforces a one-active-socket policy). Per-client addressing would require multiple sockets; the reference use cases (live gallery, sync indicator) only need one page.