Wrapper for browser-native WebSocket client. It's built using the Polymer project.
-
Import Web Components' polyfill:
<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
-
Import Custom Element:
<link rel="import" href="src/ws-element.html">
-
Start using it!
<ws-element url="ws://localhost:9999" protocol="echo-protocol"></ws-element>
Attribute | Options | Default | Description |
---|---|---|---|
url |
string | undefined |
WebSocket server endpoint to connect to. |
protocol |
string | undefined |
A subset protocol to be used as part of the communication with the server. |
Method | Parameters | Returns | Description |
---|---|---|---|
send() |
message String | Used to send messages to the server. | |
close() |
None | Close socket. |
Event | Description |
---|---|
onmessage |
Triggers when a message from the server is received. |
onerror |
Triggers when there is an error triggered by WebSocket client |
onopen |
Triggers when a socket is first open |