Installation
The WebSocket Plugin provides the WebSocket event model for AxiSpark.js. It uses an adapter to provide the transport; this guide uses the Socket.IO adapter.
Namespaces and events
Declare a WebSocket namespace with @WebSocket() and mark each event handler with @WebSocketEvent(). The event generator discovers these decorated classes and registers their handlers with the configured adapter.
Connections and rooms
Inject the current connection into a handler with @WsConnection(). The WebSocketConnection interface provides a transport-independent API for sending events and managing rooms:
Acknowledgments and errors
With the Socket.IO adapter, clients may attach an acknowledgment callback when emitting an event. A handler can respond by returning a value; the WebSocket result resolver passes that value to the acknowledgment callback.
Adapters
The @axisparkjs/websocket package defines the WebSocket plugin and the WebSocketAdapter contract. A transport integration implements that contract to initialize a server, register event definitions, start listening, and stop cleanly.