websocket

command
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

README

Liveflux WebSocket Counter Example

A minimal, runnable Liveflux example demonstrating WebSocket-based interactions.

Run

# from the liveflux repo root
go run ./examples/websocket

Then open http://localhost:8080

Screenshot

What it does

  • Renders two server-side WebSocketCounter components using liveflux.SSR
  • Mounts the client runtime via liveflux.Script()
  • Initializes a WebSocket client via the core client served at /static/websocket.js
  • Sends actions over a WebSocket connection to the /liveflux endpoint
  • Receives server-pushed updates and swaps the component HTML in place

Endpoints

  • GET / — serves the demo page containing two counter instances
  • WS /liveflux — WebSocket endpoint handled by liveflux.NewWebSocketHandler(nil)
  • GET /static/websocket.js — serves the core WebSocket client from js/websocket.js
  • GET /static/* — other static assets

Files

  • main.go — wires the HTTP mux, WebSocket handler, SSR, and static assets
  • websocket_counter.go — the component implementation (implements both Handle and HandleWS)
  • ../../js/websocket.js — Core WebSocket client that upgrades form/button actions to WS

Notes

  • The component wraps its markup with c.Root(content) (provided by liveflux.Base) to include the standard Liveflux root and required hidden fields (component, id).
  • The wrapper element includes data-flux-ws and data-flux-ws-url="/liveflux" so the JS client connects to the correct endpoint.
  • The Handle method uses url.Values (not map[string]string) to conform to the Component interface.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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