Constructor
new Server(options)
Parameters:
| Name |
Type |
Description |
options |
ServerOptions
|
|
Members
Type:
Methods
acceptWebSocketRequest(req) → {boolean|Promise.<boolean>}
This virtual method is invoked before the WebSocket connection is accepted.
req.session is already populated here if sessionMiddleware was passed to the constructor.
Parameters:
| Name |
Type |
Description |
req |
object
|
|
Returns:
A value to either accept (true) or deny (false) the WebSocket connection request.
-
Type
-
boolean
|
Promise.<boolean>
attach(app, httpServer)
Attaches the Bindary WebSocket server and XHR route to the given http server and express app.
Parameters:
| Name |
Type |
Description |
app |
object
|
The Express application instance. |
httpServer |
object
|
The Node.js http.Server instance. |
(async) broadcast(message)
Broadcasts the message to all connected clients.
Parameters:
| Name |
Type |
Description |
message |
string
|
object
|
|
close() → {Promise.<void>}
Closes the WebSocket server and terminates every currently connected WebSocket client.
Does not close the underlying http.Server itself, that remains the host app's own to manage.
Returns:
-
Type
-
Promise.<void>
onClientLoaded(message, request, client)
This abstract method is invoked when a client is loaded.
Parameters:
onDataRequest(request)
This abstract method is invoked when a DataRequest message is received from the Client.
Parameters:
onError(ex, request, client)
Handles possible exceptions that occur inside the custom implementation while processing the request.
Sending the error message to the client is usually possible.
For a custom implementation this Method should be overridden in the derived class.
Parameters:
onMessage(message)
This abstract method is invoked when a text message is received from the Client.
Parameters:
| Name |
Type |
Description |
message |
string
|
The incoming message. |
onMessageBinary(message)
This abstract method is invoked when a byte message is received from the Client.
Parameters:
| Name |
Type |
Description |
message |
Buffer
|
The incoming message. |
onOpen(req)
This abstract method is invoked when a Request through either a WebSocket or XHR connection is made.
In this fase the Session State object is no longer available on the current HttpContext, however it
is cached in the Session property of this class.
Parameters:
| Name |
Type |
Description |
req |
object
|
|
onServerError(ex)
Handles possible exceptions that occur outside the custom implementation while processing the request.
Sending the error message to the client is not possible.
For a custom implementation this Method should be overridden in the derived class.
Parameters:
| Name |
Type |
Description |
ex |
Error
|
|
removeClient(clientOrId)
Removes the specified client from the active client list. Does not unsubscribe the client from a
DataUpdateManager, since Server has no reference to one. Use ClientActivityMonitor (constructed with
a dataUpdateManager) for the combined remove-and-unsubscribe behavior, or call
dataUpdateManager.unsubscribeClient() yourself alongside this when removing clients manually.
Parameters:
| Name |
Type |
Description |
clientOrId |
string
|
Client
|
|
(async) send(client, message, xhrRequestIdopt) → {Promise.<boolean>}
Sends the message to the specified client.
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
client |
componyx.bindary.Client
|
|
|
The client to which the data will be sent. |
message |
string
|
object
|
|
|
The data message to send. |
xhrRequestId |
string
|
null
|
<optional>
|
null
|
The identifier of the current XHR request (when applicable) to
send the message as response to the current request. Without this identifier the message is stored
in the queue to be returned at the first opportunity. |
Returns:
-
Type
-
Promise.<boolean>