wilton/web/wsClient
WebSocket client for web-browsers.
More...
Functions | |
| Undefined | close (Object socket) |
| Close WebSocket connection. | |
| Undefined | isOpen (Object socket) |
| Check whether WebSocket connnection is open. | |
| Undefined | open (String url, Object|Undefined options, Function|Undefined callback) |
| Open WebSocket connection to server. | |
| Undefined | send (Object socket, Object|Array|String message, Function|Undefined callback) |
| Send message to WebSocket server. | |
| Undefined | subscribe (Object socket, String topic, Function callback) |
| Subscribe to broadcasts from WebSocket server. | |
This module allows to use WebSockets in web-browsers using "request-response" and "pub-sub" modes.
Protocol:
{ messageId: "uid", payload: msg }{ messageId: "uid", payload: msg }{ broadcast: "topic", payload: msg }Usage example:
| Undefined web_wsClient::close | ( | Object | socket | ) |
| Undefined web_wsClient::isOpen | ( | Object | socket | ) |
| Undefined web_wsClient::open | ( | String | url, |
| Object|Undefined | options, | ||
| Function|Undefined | callback | ||
| ) |
Opens WebSocket connection to server, calls callback on connection established or on timeout.
| url | String URL of the WebSocket server |
| options | Object|Undefined configuration object, see possible options below |
| callback | Function|Undefined callback to receive opened Socket or error |
UndefinedOptions
Function|Undefined function that generates unique ID's for WS messages, default value: UUID generatorFunction|Undefined function that is called with a wrapped WS message for each outgoing and incoming message, default value: console.log()Function|Undefined function that is called with error message or event object on communication error, default value: console.error()Number|Undefined timeout in milliseconds awaiting for a server response to WS message, default value: 10000 | Undefined web_wsClient::send | ( | Object | socket, |
| Object|Array|String | message, | ||
| Function|Undefined | callback | ||
| ) |
Sends message to WebSocket server, calls specified callback with a server response or on timeout
| socket | Object Socket previously opened with open() |
| message | Object|Array|String message payload that is passed to server |
| callback | Function|Undefined callback to receive response or error |
Undefined | Undefined web_wsClient::subscribe | ( | Object | socket, |
| String | topic, | ||
| Function | callback | ||
| ) |
Subscribes to broadcasts from WebSocket server, callback is called for each message that is broadcasted for the specified topic.
| socket | Object Socket previously opened with open() |
| topic | String topic name to recive broadcast on |
| callback | Function callback to receive broadcasted message or error |
Undefined
1.8.1.2