-
Notifications
You must be signed in to change notification settings - Fork 1
/
ring.html
87 lines (75 loc) · 2.29 KB
/
ring.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
81
82
83
84
85
86
87
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="/socket.io/socket.io.js"></script>
<title>{{place_name}} Doorbell</title>
</head>
<body>
<img src="{{logo_url}}" style="float: left; padding-right: 50px" alt="logo">
<div id=content>
<h1>{{place_name}} door bell</h1>
<p>Please, ring here ...and wait, please :)</p>
<div id="state" style="visibility: hidden;">Feedback...</div><br/>
{{#password}}
Password: <input id="password" type="password"/><br/><br/>
{{/password}}
<input id=bell type=button value="The bell" style="height: 100px; width: 200px;" >
{{#source_qrcode}}
<div>Tried to ring with a qr code: {{qr_state}}</div>
{{/source_qrcode}}
</div>
<script>
'use strict';
var StateEnum = {
EMPTY: 0,
RINGING: 1,
INVALID_PASSWORD: 2,
COMING: 3
}
window.onload = function() {
var messages = [],
currentState = StateEnum.EMPTY,
socket = io.connect('{{url}}'),
bellButton = document.getElementById("bell"),
state = document.getElementById("state"),
currentlyRinging = false,
password = document.getElementById("password");
//Register as a visitor
socket.emit('type', { type: 'visitor' });
bellButton.onclick = function() {
resetStateField();
socket.emit('ring', { password: (password === null) ? "" : password.value });
};
socket.on('message', function(data) {
if(data.message) {
currentState = StateEnum.COMING;
state.innerHTML = data.message;
state.style.visibility = "visible";
} else {
console.log("There is a problem: ", data);
}
});
socket.on('bad_password', function(data) {
current_state = StateEnum.INVALID_PASSWORD;
state.innerHTML = "Invalid password";
state.style.visibility = "visible";
});
socket.on('ringing', function(data) {
currentState = StateEnum.RINGING;
state.innerHTML = "== Ringing! ==";
state.style.visibility = "visible";
setTimeout(resetStateField, 10000);
});
function resetStateField() {
if (currentState != StateEnum.COMING) {
currentState = StateEnum.EMPTY;
state.innerHTML = " ";
state.style.visibility = "hidden";
}
}
}
</script>
</body>
</html>