Skip to content

Very simple example of using Cloudflare workers, durable objects and websockets.

License

Notifications You must be signed in to change notification settings

ryan-dutton/cloudflare-websockets-durable-objects-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare Worker Using Durable Objects and Websockets

This example is a dramatic simplification of the original 'Chat Room' example provided by Cloudflare. It has no concept of rooms, does not use storage or implement rate limitting. There is just a box to enter text, and the text is echoed to all connected windows.

Data is transported using websockets and routed through a single durable object. A key benefit of durable objects is that data can be pushed to clients. A worker's only solution would require some kind of polling by the client. The purpose of this example is to demonstrate that ability with minimal code.

To try it clone and run: wrangler publish or wrangler dev Note: You will need to have durable objects enabled in your Cloudflare account.

Once deployed, open multiple browser windows / tabs on the resulting URL and submit messages. The messages should appear in all connected windows almost simultaneously.

About

Very simple example of using Cloudflare workers, durable objects and websockets.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published