-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
52 lines (47 loc) · 1.88 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!doctype html>
<html>
<meta charset="utf-8">
<head>
<title>Simple Device Example</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
#messages { list-style-type: none; margin: 0; padding: 0; }
#messages li { padding: 5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
</style>
</head>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script type="text/javascript">
var device;
window.onload = function() {
console.log('Setting up socket connections:');
// We use the robot nsp (namespace) to connect to one of the devices
// in this case the led we added in our cylon robot code
device = io('http://127.0.0.1:3000/api/robots/Robot 1/devices/led');
setInterval(function() {
device.emit('toggle');
}, 1000);
device.on('message', function(payload) {
console.log('On Device');
console.log(' Event:', payload.event);
console.log(' Data:', payload.data);
$('#messages').append($('<li>').text('On Device:'));
$('#messages').append($('<li>').text(' Event:' + payload.event.toString()));
if (!!payload.data) {
$('#messages').append($('<li>').text(' Data:' + payload.data.toString()));
}
$('#messages').append($('<hr />'));
});
msg = 'You have been subscribed to Cylon sockets:' + device.nsp;
$('#messages').append($('<li>').text(msg));
};
</script>
<body>
<ul id="messages"></ul>
</body>
</html>