forked from elierotenberg/x-websocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
35 lines (30 loc) · 933 Bytes
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><my-element></title>
<!-- Importing Web Component's Polyfill -->
<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<!-- Importing Custom Elements -->
<link rel="import" href="src/x-websocket.html">
</head>
<body>
<!-- Using Custom Elements -->
<x-websocket auto url="ws://echo.websocket.org"></x-websocket>
<script>
var xws = document.querySelector("x-websocket");
console.log("xws:", xws);
xws.addEventListener("open", function() {
console.log("open");
xws.send("Hello world !");
});
xws.addEventListener("message", function(event) {
console.log("message", event.detail.data);
});
window.addEventListener('WebComponentsReady', function(e) {
// if not use "auto" property on x-websocket, then open manually with:
// xws.open();
});
</script>
</body>
</html>