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-send
attributehandlerFunction
- Function to handle the request
broadcast()
Send a message to all connected clients.target
- CSS selector for the target elementhtml
- HTML content to insertswap
(optional) - Swap method (default: ‘innerHTML’)
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’)
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-send
attributetarget
- CSS selector fromwx-target
attributetrigger
- Event that triggered the requestdata
- Form data or data fromwx-data
attributeswap
- Swap specification fromwx-swap
attribute
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)
WSXServerAdapter
Interface that framework adapters must implement.setupWebSocket()
- Set up WebSocket handlingonConnection()
- Optional connection handleronDisconnection()
- Optional disconnection handlergetApp()
- Return the framework app instance