Implement WebSocket servers for live updates.
For raw real-time power, CanxJS exposes the underlying WebSocket server (powered by Bun).
In your src/ws.ts (or similar):
import { WebSocketServer } from "canxjs";
const wss = new WebSocketServer({
open(ws) {
console.log("Client connected");
ws.subscribe("global");
},
message(ws, message) {
console.log("Received:", message);
ws.publish("global", `Echo: ${message}`);
}
});The WebSocket server shares the same port as your HTTP server, thanks to Bun's single-process model, ensuring zero latency overhead.
Have questions?
Join the discussion on GitHub