Gif Stitch is a webcam-to-animated-GIF recorder built with vanilla TypeScript and Tailwind CSS.
It has one job: show how postal’s MessagePort transport makes cross-boundary browser communication feel like normal pub/sub.
The main thread calls connectToWorker() and the worker calls connectToHost().
After the SYN/ACK handshake, addTransport() wires the result into postal’s outbound hook.
From that point on, every publish and request flows across the boundary automatically.
Request / Handle RPC
For each GIF slot, the main thread calls channel.request("encode.start", payload).
The worker’s channel.handle("encode.start", ...) encodes the frames and returns the GIF bytes.
The main thread gets a resolved Promise — no manual correlation IDs, no reply listeners.
Pub/sub for progress
While encoding each frame, the worker calls channel.publish("encode.progress", { index, percent }).
The main thread subscribed before sending the request — so the progress bar updates
live, mid-RPC, as a fire-and-forget stream alongside the pending Promise.
Zero-copy transferables
Webcam frames at 320×240 RGBA are ~0.3 MB each. Ten frames = ~3 MB per encoding request.
Calling markTransferable(payload, buffers) before the request tells the transport to
pass the ArrayBuffers to postMessage’s transfer list — zero-copy, no serialization cost.