Node.js
Without a Rails-style RPC backend, run Cabby in standalone mode. Your app signs the names of the streams a visitor may read, the browser subscribes with that signed name, and your app broadcasts with a plain HTTP request. No server-side package is needed.
1. Run Cabby
Install Cabby, then start it in standalone mode:
--noauth lets visitors connect without logging in; the signed stream names decide what each
one can read. --broadcast_adapter=http takes broadcasts over HTTP only, so you don't need Redis.
2. Sign stream names on the server
CABBY_SECRET and CABBY_BROADCAST_KEY are your app's own variables. Start your app with them
holding the same values you pass to --secret and --broadcast_key:
The helper uses ES modules. Set "type": "module" in your package.json:
// cabby.js
const SECRET = process.env. // same value as --secret
const BROADCAST_KEY = process.env. // same value as --broadcast_key
const BROADCAST_URL = process.env. ?? "http://localhost:8080/_broadcast"
Pass the signed name to the page when you render it:
res.
And print it into the page from your template (EJS here):
3. Subscribe in the browser
Install the client and import it in the browser code you bundle:
const cable =
const channel = cable.
channel.
4. Broadcast
await