hone-relay
WebSocket sync relay. Routes messages between devices in the same room. 48 tests via bun test.
Protocol
Join a room:
{"type": "join", "room": "<roomId>", "device": "<deviceId>", "token": "<deviceToken>"}
Response:
{"type": "joined", "room": "<roomId>", "device": "<deviceId>"}
Send a message:
{"from": "<deviceId>", "to": "host|broadcast|<targetDeviceId>", "room": "<roomId>", "payload": {...}}
Message Targets
"host"— send to the room’s host device"broadcast"— send to all devices in the room except the sender"<deviceId>"— send directly to a specific device
Internals
- Room-based routing — messages are routed within rooms identified by the djb2 hash of roomId
- Slot tracking — each connection gets a slot with wsId, deviceId, and roomId
- Host election — the first device to join a room becomes the host
- Buffer — messages are buffered for 60 seconds for reconnecting devices
- Auth bypass — when
auth.secretis empty, token validation is skipped (dev mode) - Rate limiting — per-connection with configurable windows
- Stateless — rooms exist only while clients are connected
Configuration
File: relay.conf
host=0.0.0.0
port=8443
auth.secret=<shared-secret>
Ports
- 8443 — HTTP
- 8444 — WebSocket
Build
Perry-compiled or runs on Bun:
cd hone-relay && perry compile src/app.ts --output hone-relay