Skip to content

A Polymer 2.0 element to ease the usage of WebSockets.

License

Notifications You must be signed in to change notification settings

arkihillel/web-socket

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License Published on webcomponents.org

<web-socket>

A Polymer 2.0 element to ease the usage of WebSockets.

Usage

<web-socket auto
            url="{{url}}"
            protocols="{{protocols}}"
            state="{{state}}"
            last-request="{{request}}"
            last-response="{{response}}"
            last-error="{{error}}"
            on-error="_handleError"
            on-message="_handleMessage"
            on-open="_handleOpen"
            on-close="_handleClose"
            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
  • handle-as = Empty for the plain message or json to get it parsed
  • 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

Events:

  • onError = Sends an event when the socket returns an error
  • onMessage = Sends an event when a new frame is received from the socket
  • onOpen = When the connection is established
  • onClose = When the connection is closed

About

A Polymer 2.0 element to ease the usage of WebSockets.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HTML 100.0%