/
zombocom-client.html
73 lines (66 loc) · 1.73 KB
/
zombocom-client.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Zombocom</title>
<style>
body {
font-family:sans-serif;
font-size:2em;
text-align:center;
font-weight:bold;
}
article,
section {
display:block;
}
article { margin:2em }
#zombocom {
padding:4em 2em;
-webkit-animation-name: tilt;
-webkit-animation-duration: 50s;
-webkit-animation-iteration-count: infinite;
}
@-webkit-keyframes tilt {
0% { -webkit-transform: rotate(-24deg); }
100% { -webkit-transform: rotate(24deg); }
}
#status { color: white }
#status.open { background-color:green }
#status.closed { background-color:blue }
#status.failed { background-color:red }
</style>
</head>
<body>
<article>
<section id=status>Not connected</section>
<section id=zombocom></section>
</article>
<script>
var conn = {},
serverUri = "ws://localhost:8888",
zombocom = document.getElementById("zombocom"),
state = document.getElementById("status");
function openConnection() {
if (!conn.readyState || conn.readyState > 1) {
conn = new WebSocket( serverUri );
conn.onopen = function () {
state.innerHTML = "Socket Open";
state.className = "open";
};
conn.onmessage = function( event ) {
zombocom.innerHTML = event.data || "";
};
conn.onclose = function( event ) {
state.innerHTML = "Socket Closed";
state.className = "closed";
};
}
}
if (!!window.WebSocket) {
openConnection();
} else {
state.innerHTML = "Sockets not supported";
state.className = "failed";
}
</script>