browser

command
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 14 Imported by: 0

README

Browser end-to-end demo

The shortest path from a fresh clone to "I see realtime data in a browser." One Go file, one HTML file, no Redis, no token plumbing.

Run

go run ./examples/browser
# browser demo: open http://localhost:8000

Then open http://localhost:8000 in any modern browser. The page subscribes to public:demo.system.heartbeat via centrifuge-js and renders the JSON heartbeat the Go server publishes every second.

Ctrl-C shuts the server down cleanly.

What it shows

  • Server side: parsec.NewRun in a goroutine → OpenPublic → a 1 Hz Publish loop. The same Broker().Node() powers centrifuge.NewWebsocketHandler mounted at /connection/websocket.
  • Client side: vanilla Centrifuge("ws://localhost:8000/connection/websocket"), one newSubscription(channel), one on("publication", ...) callback that prepends incoming rows to a <ul>.

The channel is public — no token is required to subscribe. For the private-channel flow, see docs/src/getting-started/browser-client.md.

File map

File Purpose
main.go Go server that boots parsec, embeds the HTML page, and publishes a heartbeat
index.html Single-file browser client using centrifuge-js over a CDN

Things to try

  • Open the page in two browser tabs. Both subscriptions receive every publication — fan-out is the broker's default behaviour.
  • kill -STOP the server; reload the page. Watch the status pill flip to "disconnected" with the reason from the centrifuge client.
  • Resume with kill -CONT; the client auto-reconnects and resumes the feed.

For a private-channel walkthrough (token mint → browser presents JWT → subscribe authorization), read the documentation page linked above.

Documentation

Overview

Browser end-to-end demo. Boots a parsec instance, hosts a single HTML page that connects via centrifuge-js, and pushes a heartbeat publication every second. Open http://localhost:8000 in a browser after running:

go run ./examples/browser

The page renders incoming publications as a live log so you can see the broker → websocket → browser path end-to-end.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL