A Polymer 2.0 element to ease the usage of WebSockets.
Watch a live demo ↗
- Install all dependencies via Bower in the repo directory:
bower install
- Run the demo automatically in your browser via the Polymer development server part of Polymer CLI from the project directory:
polymer serve --open
<web-socket auto
url="{{url}}"
protocols="{{protocols}}"
state="{{state}}"
last-request="{{request}}"
last-response="{{response}}"
last-error="{{error}}"
verbose>
</web-socket>
The above example illustrates the usage of <web-socket>
in a Polymer app.
Attributes explained:
- auto = Enables auto connection with page load
- url = The URL to which to connect
- protocols = An optional property to provide a single protocol string or an array of protocol strings.
- state = The current state of the WebSocket connection. Notifies about state changes: WebSocket.readyState
- last-request = The most recent request made by this web-socket element.
- last-response = The most recent response received by this web-socket element.
- last-error = The most recent error received by this web-socket element. If any error occurred.
- verbose = Enables verbose mode
Almost all demo references uses wss://echo.websocket.org/ as WebSocket-Server. This demo makes no difference. If you search for a local alternative, you can get up and running in minutes with httpwebsockethandler by SevenW.