-
Notifications
You must be signed in to change notification settings - Fork 557
Description
Please support auto-response for binary frames in WebSockets so that Durable Objects can support protocols like MQTT without waking from hibernation.
i.e. code like this should work:
this.ctx.setWebSocketAutoResponse(
new WebSocketRequestResponsePair(
new Uint8Array([0xc0, 0x00]), // PINGREQ
new Uint8Array([0xd0, 0x00]), // PINGRESP
)
);
MQTT is a widespread protocol in the hardware/IoT world, and the code above is the heartbeat protocol.
However: setWebSocketAutoResponse only takes strings. WebSockets have text frames (opcode 0x01) and binary frames (opcode 0x02) and only text frames are supported for auto-response.
Context is that I'm using DO (and agents) as the back-end for AI consumer hardware, and given these are always-on connected devices, each DO is waking 1,440 times daily to handle the device's PINGREQ in onMessage -- defeats the purpose of hibernation.
(It doesn't look like there is any fundamental architectural limitation preventing this in workerd, only that strings are assumed all the way down. But there might be something outside the scope of workers itself.)
Many thanks