Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

hunsalz/web-socket

Repository files navigation

Build Status License Published on webcomponents.org

Watch <web-socket>↗ live

A Polymer 3.0 element to ease the usage of WebSockets.

Install dependencies and run the demo locally

  1. Build <web-socket> in the repo directory:
$ polymer build
  1. Run the demo automatically in your browser:
$ polymer serve --open

Usage

Example of <web-socket>:

<web-socket url="{{url}}"
            protocols="{{protocols}}"
            state="{{state}}"
            last-request="{{request}}"
            last-response="{{response}}"
            last-error="{{error}}"
            retry
            connect-attempts="{{connectAttempts}}">
</web-socket>

Attributes explained:

  • url = Describes the WebSocket server URL
  • protocols = Describes a single protocol string or a collection of protocol strings
  • state = Provides the current state of the WebSocket connection. Notifies about WebSocket.readyState changes.
  • 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.
  • retry = Redelivers messages after a connection break-down
  • connectAttempts = Counts and notify re-connection attempts

Run your own prototype WebSocket-Server without great effort

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.