Constructor
new ConnectionManager(ws, req, controller, do_bootstrapopt)
Initialize the connection manager.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ws |
WebSocket | the open connection |
||
req |
express/Request | the connection request |
||
controller |
object | the connection's controller |
||
do_bootstrap |
boolean |
<optional> |
true | if false, the socket connection will NOT be automatically bootstrapped to use transactional communication |
- Source:
Methods
(private) _bootstrap(socket)
Bootstrap a websocket connection to use transactional processing. When new messages come in, validate them and handle them as requests or responses based on their data.
Name | Type | Description |
---|---|---|
socket |
WebSocket |
- Source:
(private) _is_json(string) → {boolean}
Checks if a string is valid JSON
Name | Type | Description |
---|---|---|
string |
- Source:
- Type
- boolean
(private) _request(endpoint, data, handler) → {*|boolean|void}
Send a request to the client managed by this class, and wait for a valid response.
Name | Type | Description |
---|---|---|
endpoint |
string | client endpoint to be called |
data |
object | body data of the request |
handler |
function | callback function for a valid response |
- Source:
- Type
- * | boolean | void
on_close(callbackopt) → {Promise.<void>}
Register a callback or promise to execute on close of the connection.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
callback |
function |
<optional> |
false |
- Source:
- Type
- Promise.<void>
on_open(callbackopt) → {Promise.<void>}
Register a callback or promise to execute on open of the connection.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
callback |
function |
<optional> |
false |
- Source:
- Type
- Promise.<void>
process(t) → {module:flitter-socket/Transaction~Transaction}
Process a transaction by calling its endpoint method. If the transaction is resolved, delete it.
Name | Type | Description |
---|---|---|
t |
module:flitter-socket/Transaction~Transaction |
- Source:
the processed transaction
transaction(topt) → {null|module:flitter-socket/Transaction~Transaction}
Kind of a catch-all for registering transactions. If no transaction is provided, gracefully return. If a transaction object is provided, register it in this.active_transactions by its ID. Otherwise if it is a string, return the active transaction with that ID.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
t |
module:flitter-socket/Transaction~Transaction | string |
<optional> |
false |
- Source:
- Type
- null | module:flitter-socket/Transaction~Transaction
validate_incoming_message(msg) → {object|null}
Validates that a transaction is a valid flitter-sockets spec transaction. If it is, return the transaction's data. Otherwise, send a module:flitter-socket/ClientErrorTransaction~ClientErrorTransaction.
Name | Type | Description |
---|---|---|
msg |
string | the incoming client message |
- Source:
- Type
- object | null