ewnd9 / workers-chat-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cloudflare Edge Chat Demo

Forked from https://github.com/cloudflare/workers-chat-demo

How does it work?

  • This chat app uses a Durable Object to control each chat room.
  • Users connect to the object using WebSockets.
  • Messages from one user are broadcast to all the other users.
  • The chat history is also stored in durable storage, but this is only for history.
  • Real-time messages are relayed directly from one user to others without going through the storage layer.

Install

$ yarn install

Usage

$ yarn start:dev # http://localhost:8787/

Publishing

$ npm i -g @cloudflare/wrangler
$ wrangler login
# required paid plan ($5+/month)
$ wrangler publish

How to uninstall

Modify wrangler.toml to remove the durable_objects bindings and add a deleted_classes migration. The bottom of your wrangler.toml should look like:

[durable_objects]
bindings = [
]

# Indicate that you want the ChatRoom and RateLimiter classes to be callable as Durable Objects.
[[migrations]]
tag = "v1" # Should be unique for each entry
new_classes = ["ChatRoom", "RateLimiter"]

[[migrations]]
tag = "v2"
deleted_classes = ["ChatRoom", "RateLimiter"]

Then run wrangler publish, which will delete the Durable Objects and all data stored in them. To remove the Worker, go to dash.cloudflare.com and navigate to Workers -> Overview -> edge-chat-demo -> Manage Service -> Delete (bottom of page)

About

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:TypeScript 84.7%Language:CSS 10.2%Language:HTML 5.1%