-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonitor.html
80 lines (67 loc) · 1.98 KB
/
monitor.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
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="/socket.io/socket.io.js"></script>
<title>{{place_name}} Doorbell</title>
</head>
<body>
<h1>{{place_name}} door bell Monitor</h1>
<div id="content" style='width: 500px; height: 300px; margin: 0 0 20px 0; border: solid 1px #999; overflow-y: scroll;'>
</div>
<div id="infos">
State : <input id=state type=text value="deco"><br/>
</div>
<br/>
<audio controls id=ring>
<source src="mgs_codec.ogg" type="audio/ogg">
<source src="mgs_codec.mp3" type="audio/mpeg">
</audio>
<input id="ack" type="button" value="Acknowledge" style="height: 100px; width: 200px;" />
<script>
'use strict';
window.onload = function() {
var messages = [],
socket = io.connect('{{url}}'),
sendButton = document.getElementById("ack"),
content = document.getElementById("content"),
state = document.getElementById("state"),
ring = document.getElementById("ring");
sendButton.onclick = function() {
socket.emit('ack', { message: "coming!" });
}
// I'm a host
socket.emit('type', { type: 'host' });
// Message to display
socket.on('message', function (data) {
if(data.message) {
messages.push(data.message);
var html = '';
for(var i = 0; i < messages.length; i++) {
html += messages[i] + '<br />';
}
content.innerHTML = html;
ring.play(); // Ring !
} else {
console.log("There is a problem:", data);
}
});
// Connection state
socket.on('connect', function () {
state.value = "connected !";
state.style = "background-color: green;";
ring.loop = false;
});
socket.on('connecting', function () {
state.value = "connecting !";
});
socket.on('disconnect', function() {
state.value = "disconnected !";
state.style = "background-color: red;";
ring.loop = true; // to notice disconnection
ring.play();
});
}
</script>
</body>
</html>