Have questions? Stuck? Please check our FAQ for some common questions and answers.

UI Service - WebSocketService

WebSocketService is an Angular Factory in the Remote module with the name websocket.js. It provides functions to request and receive information from the server via the websocket. To use these functions, see the documentation on injecting Angular services.

NameSummary
resetSidResets the event sequence identifier back to 0.
resetStateResets all internal variables back to their default value.
createWebSocketCreates a new WebSocket with options.
bindHandlersBinds functions to response messages.
unbindHandlersUnbinds handlers for response messages.
addOpenListenerBind a function to WebSocket open event.
removeOpenListenerRemove handler for WebSocket open event.
sendEventCreates an event message and sends it via the WebSocket.

Function Descriptions

resetSid

Resets the event sequence identifier back to 0. This function is only used in testing.

Example UsageArgumentsReturn Value
wss.resetSid();nonenone

resetState

Resets all internal service variables back to their default value. This function is only used in testing.

Example UsageArgumentsReturn Value
wss.resetState();nonenone

createWebSocket

Creates a new WebSocket with options.

Example UsageArgumentsReturn Value

wss.createWebSocket(opts, host);

opts - an object containing:

wsport: a websocket port other than the default 8181

host - the host address to use, defaults to current host

the URL in which the websocket was opened

bindHandlers

Binds functions to response messages.

Example UsageArgumentsReturn Value
wss.bindHandlers(handlerMap);

handlerMap - an object containing:

<server response event name>: <function reference to execute on response>

none

null if handlerMap was falsy or an empty object

unbindHandlers

Unbinds handlers for response messages. This function is expected to be called when a view is destroyed.

Example UsageArgumentsReturn Value
wss.unbindHandlers(handlerMap);handlerMap - the same object as was used to bindHandlers

none

null if handlerMap was falsy or an empty object

addOpenListener

Bind a function to WebSocket open event.

Example UsageArgumentsReturn Value
wss.addOpenListener(callback);callback - function reference to be executed on WebSocket open

object containing:

id: this listener's ID

cb: callback

error: 'No callback defined' if there was an error

removeOpenListener

Remove handler for WebSocket open event.

Example UsageArgumentsReturn Value
wss.removeOpenListener(lsnr);lsnr - the object returned from addOpenListenernone

sendEvent

Creates an event message and sends it via the WebSocket.

Example UsageArgumentsReturn Value
wss.sendEvent(evType, payload);

evType - string of the event type to send to the server

payload - object containing the event's payload

none, but sends the event to the server
  • No labels