Live cursors with WebSockets

WebSockets talk both ways over one connection, which suits frequent small messages like cursor positions. Jeasx handles them without any plugin.

Unlike Server-Sent Events (see /sse), which only push from the server to the browser, both sides can send at any time. A few lines in FASTIFY_SERVER of jeasx.config.js listen for the upgrade event of the server and pass the request to Fastify, which works the same with Node and Bun. The route /websocket/socket takes over the connection with reply.hijack() and speaks the WebSocket protocol in about 150 lines. Open this page in a second window and move your mouse in the room below.

Room

Connecting…

Move your pointer here · click to send a ripple

Waiting for the server…0 sent · 0 received

The room lives in the memory of one server process. Serverless platforms like Vercel don't keep connections open, so the WebSocket only works when the server runs on its own (e.g. with Docker).