WSXServer
The main server class that manages WebSocket connections and request handling.Constructor
adapter- A WSXServerAdapter implementation (Express, Hono, or custom)
Methods
on()
Register handlers for WebSocket requests.handler(optional) - Handler name to match againstwx-sendattributehandlerFunction- Function to handle the request
onJson()
Register handlers for JSON message channels. Accepts either a specific channel or a catch-all handler.channel(optional) - JSON channel name to handlehandler- Function invoked withWSXJSONMessageobjects
onStream()
Register handlers for binary stream messages. Works with channel-specific or catch-all handlers.channel(optional) - Stream channel name to handlehandler- Function invoked withWSXStreamMessagemetadata and the binary payload
broadcast()
Send a message to all connected clients.target- CSS selector for the target elementhtml- HTML content to insertswap(optional) - Swap method (default: ‘innerHTML’)
broadcastJson()
Publish a JSON payload to every connected client.channel- Logical channel namedata- JSON-serializable payloadoptions(optional) - Additional metadata or explicit identifier
broadcastStream()
Send a binary payload to every connected client.channel- Stream channel namepayload- Binary data (ArrayBufferor typed array)options(optional) - Metadata or explicit stream identifier
sendToConnection()
Send a message to a specific connection.connectionId- ID of the target connectiontarget- CSS selector for the target elementhtml- HTML content to insertswap(optional) - Swap method (default: ‘innerHTML’)
sendJsonToConnection()
Send a JSON message to a specific connection.connectionId- Target connection IDchannel- JSON channel namedata- JSON-serializable payloadoptions(optional) - Metadata or explicit message identifier
undefined if the connection is not found
Example:
sendStreamToConnection()
Send a binary stream frame to a specific connection.connectionId- Target connection IDchannel- Stream channel namepayload- Binary payload (ArrayBufferor typed array)options(optional) - Metadata or explicit identifier
undefined if the connection is missing
Example:
getConnections()
Get all active connections.getConnectionCount()
Get the number of active connections.removeConnection()
Remove a connection from the server.connectionId- ID of the connection to remove
getApp()
Get the underlying framework app instance.WSXRequest
Interface representing an incoming WebSocket request.id- Unique identifier for the requesthandler- Handler name specified inwx-sendattributetarget- CSS selector fromwx-targetattributetrigger- Event that triggered the requestdata- Form data or data fromwx-dataattributeswap- Swap specification fromwx-swapattribute
WSXResponse
Interface representing a response to send back to the client.id- Must match the request IDtarget- CSS selector for the element to updatehtml- HTML content to insertswap- How to insert the content (innerHTML, outerHTML, etc.)oob- Array of out-of-band updates for other elements
WSXOOBUpdate
Interface for out-of-band updates.target- CSS selector for the element to updatehtml- HTML content to insertswap- How to insert the content
WSXConnection
Interface representing a WebSocket connection.id- Unique identifier for the connectionsessionData- Object for storing session-specific datasend()- Method to send data to the clientclose()- Method to close the connection
WSXHandler
Type definition for handler functions.request- The incoming requestconnection- The connection that sent the request
WSXResponse- Single responseWSXResponse[]- Array of responsesvoid- No response (useful for side effects only)
WSXBinaryData
Union type representing allowed binary payloads.WSXJSONMessage
Structure passed to JSON handlers and received on the client.WSXJSONHandler
Type definition for JSON message handlers.WSXJSONSendOptions
Optional options when sending JSON messages.WSXStreamMessage
Metadata describing a binary stream frame.WSXStreamHandler
Type definition for stream handlers.WSXStreamSendOptions
Optional options when sending binary stream frames.WSXServerAdapter
Interface that framework adapters must implement.setupWebSocket()- Set up WebSocket handlingonConnection()- Optional connection handleronDisconnection()- Optional disconnection handlergetApp()- Return the framework app instance

