-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
28 lines (27 loc) · 697 Bytes
/
index.html
File metadata and controls
28 lines (27 loc) · 697 Bytes
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
<!doctype html>
<html>
<head>
<title>Socket.io Simple Example</title>
</head>
<body>
<div id="light">Unknown</div>
<button id="toggleButton">Toggle</button>
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
var socket = io();
$('#toggleButton').on('click', function() {
socket.emit('toggle', {state:true});
});
socket.on('light', function(light) {
console.log(light);
if (light.state) {
$('#light').text('ON');
}
else {
$('#light').text('off');
}
});
</script>
</body>
</html>