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.
Name | Summary |
---|---|
resetSid | Resets the event sequence identifier back to 0. |
resetState | Resets all internal variables back to their default value. |
createWebSocket | Creates a new WebSocket with options. |
bindHandlers | Binds functions to response messages. |
unbindHandlers | Unbinds handlers for response messages. |
addOpenListener | Bind a function to WebSocket open event. |
removeOpenListener | Remove handler for WebSocket open event. |
sendEvent | Creates 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 Usage | Arguments | Return Value |
---|---|---|
wss.resetSid(); | none | none |
resetState
Resets all internal service variables back to their default value. This function is only used in testing.
Example Usage | Arguments | Return Value |
---|---|---|
wss.resetState(); | none | none |
createWebSocket
Creates a new WebSocket with options.
Example Usage | Arguments | Return Value |
---|---|---|
wss.createWebSocket( |
wsport: a websocket port other than the default 8181
| the URL in which the websocket was opened |
bindHandlers
Binds functions to response messages.
Example Usage | Arguments | Return Value |
---|---|---|
wss.bindHandlers(handlerMap ); |
<server response event name>: <function reference to execute on response> | none
|
unbindHandlers
Unbinds handlers for response messages. This function is expected to be called when a view is destroyed.
Example Usage | Arguments | Return Value |
---|---|---|
wss.unbindHandlers(handlerMap ); | handlerMap - the same object as was used to bindHandlers | none
|
addOpenListener
Bind a function to WebSocket open event.
Example Usage | Arguments | Return Value |
---|---|---|
wss.addOpenListener(callback ); | callback - function reference to be executed on WebSocket open | object containing: id: this listener's ID cb: error: 'No callback defined' if there was an error |
removeOpenListener
Remove handler for WebSocket open event.
Example Usage | Arguments | Return Value |
---|---|---|
wss.removeOpenListener(lsnr ); | lsnr - the object returned from addOpenListener | none |
sendEvent
Creates an event message and sends it via the WebSocket.
Example Usage | Arguments | Return Value |
---|---|---|
wss.sendEvent(evType , payload ); |
| none, but sends the event to the server |