lukeed / worktop

The next generation web framework for Cloudflare Workers
MIT License
1.66k stars 42 forks source link

WebSocket support #49

Closed universse closed 3 years ago

universse commented 3 years ago

Hi. It would be cool if worktop can support WebSocket in the future. It's especially powerful when paired with Durable Object, as explained here.

I have been using https://github.com/uNetworking/uWebSockets.js. and quite like their API as I can define both http and ws routes.

app
  .ws(`/room/:id`, wsRouteConfig)
  .post('/project/create', projectCreateRoute)
  .any(`/*`, (res, _req) => {
    res.writeStatus(`404 Not Found`).end()
  })
  .listen(3001, () => {})

I'm considering switching to Cloudflare since I won't have to think about scaling infrastructure, which is enticing.

universse commented 3 years ago

I just re-read the doc and it's just been added. Nice work 🚀. Any chance worktop could handle ping/pong messages by default as well?

lukeed commented 3 years ago

Hi,

Yes, preliminary websocket support was added in 0.6.0. This is single channel support – aka, WS handler for a single connection. There's no DO integration yet, which means that broadcasting/synchronizing WS connections is not currently possible.

Worktop will add official DO support once Durable Objects are ready to leave their beta phase.

Until then, you can attach DOs yourself, but you'll have to do a lot of stuff manually.

Any chance worktop could handle ping/pong messages by default as well?

No – this is application-specific and while it may sound like a harmless default, Worktop is only going to put stuff in your output if you asked for it or if you put it there.

Closing, as this is on the roadmap but its release date depends on DO's date.