A Polymer element to ease the use and configuration of WebSockets.
<web-socket url="ws://echo.websocket.org"
auto json
on-open="_onOpen"
on-close="_onClose"
on-message="_onMessage"
on-error="_onError">
</web-socket>
The above example shows how to establish a WebSocket connection with
<web-socket>
in a Polymer app. This simple
declarative element definition is:
- Establishing a connection to
ws://echo.websocket.org
. - Automatically connecting on page load.
- Parsing and stringifying JSON automatically.
- Automatically reconnecting in the event of an unclean close event (a default behaviour of this library - no configuration required through properties).
- Setting up event handlers to functions declared externally (
_onOpen
,_onClose
, etc - defined by a parent element, such as a page).
You can install <web-socket>
with Bower
bower install web-socket
You can also view the documentation, try the demo and run the tests.