Methods
_setup_app_ws(ws, app_wss)
Sets up a websocket message event handler that can be used the client to run messages through the tokenized transition framework.
The message handler parses the body data, which should be a JSON parseable string. This is parsed into the body of the message.
The body shoud have the following fields:
- message - The message is itself an object with application defined fields. One required field will be
server_id. - transition - The name of the transition.
- ping_id - for ping message
The message handler checks to see if the server_id field on the message.
If the id is not on the object, this method attempts to treat the message as a
ping/pong message. If the field server_id is on the message, then this method calls upon the transition processor's
method, ws_transition, which performs similar operations to the HTTP path handler.
The close event handler is also set up. This calls close_wss_session which remove the descriptor from the going_sessions
table.
Parameters:
| Name | Type | Description |
|---|---|---|
ws |
object | |
app_wss |
object |
- Source:
_setup_sitewide_ws(ws, auth_wss)
Parameters:
| Name | Type | Description |
|---|---|---|
ws |
object | web socket connection |
auth_wss |
object |
- Source:
add_service(port) → {Object}
Calls the framework (node.js) createServer method and then creates a new WebSocket wrapper with the server as its parameter. Returns the web socket server wrapper.
Parameters:
| Name | Type | Description |
|---|---|---|
port |
number |
- Source:
Returns:
- WebSocketServer - the web socket server wrapper.
- Type
- Object
add_ws_session(ws)
Called by _setup_app_ws.
This method creates an id for the websocket connection and maps the session into going_sessions.
This method then sends a message to the client indicating that the connection has taken place.
Parameters:
| Name | Type | Description |
|---|---|---|
ws |
object | web socket server |
- Source:
close_suspects()
Closes off client connections that are not responding to pings.
- Source:
close_wss_session(ws) → {boolean}
Closes out a web socket connection.
Parameters:
| Name | Type | Description |
|---|---|---|
ws |
object | web socket client connection |
- Source:
Returns:
- Type
- boolean
do_pings(caller)
Pings the clients to see if they will respond.
Parameters:
| Name | Type | Description |
|---|---|---|
caller |
function |
- Source:
initialize(conf, app)
This method takes in a configuration object which should have a websocket field.
The websocket field in turn must have two fields:
- port_names - a list of strings that name ports having meaning to the application.
- defs - a map of the port names to port numbers.
The constructor provides default port handlers, "ws_port", "wss_app_port". But, an application may add to these.
This method add websocket servers for each port identified by port_names. After each port server is created,
this method calls the port handler corresponding to the port name, passing the web socket server wrapper.
The port handlers set up the web socket event handlers for fielding messages and errors.
Parameters:
| Name | Type | Description |
|---|---|---|
conf |
object | |
app |
object |
- Source:
ping(ws)
Send a ping message to a single client.
This adds a field to the ws, the socket connection wrapper. The field is _app_x_isAlive.
A message containing the _app_x_ws_id is sent to the client. _app_x_ws_id is another
field added to the socket connection wrapper and is used to find the connection wrapper in the
going_sessions table belonging to this class.
Parameters:
| Name | Type | Description |
|---|---|---|
ws |
object | web socket server |
- Source:
ponged(ws)
This method must called in response to the ping call in order for the websocket connection to be considered to be alive.
Parameters:
| Name | Type | Description |
|---|---|---|
ws |
object | web socket server |
- Source:
send_to_ws(ws, data)
Given the websocket wrapper with the send method, this send data to the connected client.
The data must be stringifiable.
Parameters:
| Name | Type | Description |
|---|---|---|
ws |
object | |
data |
object |
- Source:
send_ws(ws_id, data)
Send a message on the identified web sockets.
This method creates a wrapper for the actual data being sent and attach it to the data field of the wrapper.
It also puts the id of the wrapper and assigns it as the value to the ws_id field of the message.
Parameters:
| Name | Type | Description |
|---|---|---|
ws_id |
string | |
data |
object |
- Source:
send_ws_outofband(token_key, data)
This method is a wrapper of the method send_to_ws.
This method pertains to transtion handling, and so it requires the transition
token to find the websocket connection wrapper. It sends any data that can be
stringified.
The outofband part of the name usually refers to the situation in data is sent at times other than when a transtion action is being performed or before the action has been completed.
Parameters:
| Name | Type | Description |
|---|---|---|
token_key |
string | tansition token |
data |
object |
- Source:
set_contractual_filters(trans_processor, user_processor, mime_processor)
Parameters:
| Name | Type | Description |
|---|---|---|
trans_processor |
object | an instance of the class |
user_processor |
object | |
mime_processor |
object |
- Source:
setup_app_ws(app_wss)
This method handles the connection event. This method filters out messages that are not on th /shared_auth
path of the web socket. If the connection is on the path, then it completes the connection setup
setting up the handler for events: message, close, error.
Sets up a websocket that can be used the client to run messages through the tokenized transition framework.
Access may be available to a transition engine that is customized to send data messages (in quasi real time) to the client interfaces.
This method filters out messages that are not on th transitional path of the web socket.
Parameters:
| Name | Type | Description |
|---|---|---|
app_wss |
object | a web socket handle |
- Source:
setup_sitewide_ws(auth_wss)
This method handles the connection event. This method filters out messages that are not on th /shared_auth
path of the web socket. If the connection is on the path, then it completes the connection setup
setting up the handler for events: message, close, error.
Parameters:
| Name | Type | Description |
|---|---|---|
auth_wss |
object | a web socket handle |
- Source:
start_checking_pings()
Called by add_ws_session if it has not yet been called.
It is possible it will be called again if at some point it was turned off and if
add_ws_session is called.
- Source:
ws_connection_attempt(proc_ws_token, sitewide_socket)
Parameters:
| Name | Type | Description |
|---|---|---|
proc_ws_token |
string | |
sitewide_socket |
object |
- Source:
ws_shutdown(ws)
Parameters:
| Name | Type | Description |
|---|---|---|
ws |
object | web socket server |
- Source:
ws_sitewide_message_handler(data, ws)
Takes the message data and parses as JSON.
If the object produced has a ping_id, this method responds to the message by calling ponged.
The sitewide websocket server locates the websocket session descriptor by using a token field on th message body.
The body must also have an action field. This method provides to action handlers, setup and logout.
The setup pathway adds the web socket server wrapper to the going_ws_sitewide_sessions[token] array.
This method will create the array the first time the token is seen. Ideally, the token will be a session identifier (token),
and will keep connections to the websocket clients.
In a browser, different web socket connections for a single session would be the result of opening a number of tabs and windows belonging to the session. When the session is ended, one window or tab will initiate the logout and the rest of the interfaces will receive the logout message from this handler.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Buffer | |
ws |
object |
- Source: