8000 Add chat example by nhooyr · Pull Request #190 · coder/websocket · GitHub
[go: up one dir, main page]

Skip to content

Add chat example #190

New issue

Have a question abou 8000 t this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 17, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup example README
  • Loading branch information
nhooyr committed Feb 17, 2020
commit 4908f7846fcd785df64d1ed1070826ea282568ab
15 changes: 7 additions & 8 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Chat Example

This directory contains a full stack example
of a simple chat webapp using nhooyr.io/websocket.
This directory contains a full stack example of a simple chat webapp using nhooyr.io/websocket.

```bash
$ cd example
Expand All @@ -15,11 +14,11 @@ Visit the printed URL to submit and view broadcasted messages in a browser.

## Structure

The frontend is contained in `index.html`, `index.js` and `index.css`. It setups the
DOM with a form at the buttom to submit messages and at the top is a scrollable div
that is populated with new messages as they are broadcast. The messages are received
via a WebSocket and messages are published via a POST HTTP endpoint.
The frontend is contained in `index.html`, `index.js` and `index.css`. It sets up the
DOM with a scrollable div at the top that is populated with new messages as they are broadcast.
At the bottom it adds a form to submit messages.
The messages are received via the WebSocket `/subscribe` endpoint and published via
the HTTP POST `/publish` endpoint.

The server portion is `main.go` and `chat.go` and implements serving the static frontend
assets as well as the `/subscribe` WebSocket endpoint for subscribing to
broadcast messages and `/publish` for publishing messages.
assets, the `/subscribe` WebSocket endpoint and the HTTP POST `/publish` endpoint.
0