Serving
Binary channels
Open named two-way channels to move video frames, images and files between Java and the page without base64 or JSON.
For big or binary data, such as video frames, images and files, open a named two-way channel. No base64 and no JSON. Available since 0.2.3.
Open a channel
BinaryChannel frames = window.openChannel("frames"); // open it before the page loads
frames.onMessage(bytes -> handle(bytes));
frames.send(ByteBuffer.wrap(pixels)); // never blocks; returns false if refusedconst frames = jolt.channel("frames");
frames.onMessage(data => { /* ArrayBuffer */ });
frames.send(new Uint8Array([1, 2, 3]));Behaviour
- The page connects and reconnects by itself.
onOpen,onCloseandisOpen()tell you the state. ChannelOptions.newestOnly()keeps only the latest message for a slow page, which suits live video.withMaxQueuedBytesbounds the queue.- Callbacks run on a thread of their own, not the UI thread.
- A channel is a WebSocket on
127.0.0.1, accepted only from origins your SecurityPolicy trusts and with a per-run secret. - On Linux, use
loadResources(notloadHtml) for pages that open channels.