Node.js WebSocket server interface for @reticulum/core, backed by ws.
The @reticulum/core core ships the WebSocketClientInterface (a WebSocket client, browser-safe via Web APIs). A WebSocket server, however, cannot run in a browser and Node does not ship one natively. This companion listens for inbound WebSocket connections and spawns a WebSocketClientInterface per accepted connection, mirroring TCPServerInterface.
npm install @reticulum/websocket-server-node
This depends on @reticulum/core and ws automatically.
import { Reticulum } from "@reticulum/core";
import { WebSocketServerInterface } from "@reticulum/websocket-server-node";
const rns = new Reticulum();
const server = new WebSocketServerInterface({ listenPort: 4242 });
server.addEventListener("connection", (event) => {
// Each accepted connection is a spawned WebSocketClientInterface; attach it
// to the transport. The server copies its bitrate onto each spawned client.
rns.addInterface(event.detail, false);
});
await server.connect();
Set framing: "kiss" for RNode-style KISS-over-WebSocket peers (defaults to raw).
| Export | Interface id | Runtime deps | Notes |
|---|---|---|---|
WebSocketServerInterface |
ws-server |
ws |
Spawns a WebSocketClientInterface per accepted connection; server itself never carries packets |
Note: the interface registry in
@reticulum/nodedoes not registerws-server(that would force it to depend onws). Register it yourself withregisterInterfaceif you want it in a schema enumeration.
Licensed under the EUPL 1.2. See the monorepo README for project-wide information.
Description
Node.js WebSocket server interface for
@reticulum/core.The browser-safe core (
@reticulum/core) ships only theWebSocketClientInterface— a server needs a WebSocket server, which browsers cannot run and Node does not ship natively. This companion listens for inbound WebSocket connections and spawns aWebSocketClientInterfaceper accepted connection (adopting the socket), mirroringTCPServerInterface. Backed by ws.