cloudflare / cloudflare/workerd

Feature request: binary support for setWebSocketAutoResponse

Open
#6,062 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.