forked from Forceu/barcodebuddy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.php
More file actions
executable file
·312 lines (274 loc) · 10.4 KB
/
Copy pathscreen.php
File metadata and controls
executable file
·312 lines (274 loc) · 10.4 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<?php
/**
* Barcode Buddy for Grocy
*
* PHP version 7
*
* LICENSE: This source file is subject to version 3.0 of the GNU General
* Public License v3.0 that is attached to this project.
*
* A screen to supervise barcode scanning.
*
* @author Marc Ole Bulling
* @copyright 2019 Marc Ole Bulling
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU GPL v3.0
* @since File available since Release 1.0
*/
require_once __DIR__ . "/incl/configProcessing.inc.php";
require_once __DIR__ . "/incl/config.inc.php";
$CONFIG->checkIfAuthenticated(true);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="apple-touch-icon" sizes="57x57" href="./incl/img/favicon/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="./incl/img/favicon/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="./incl/img/favicon/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="./incl/img/favicon/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="./incl/img/favicon/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="./incl/img/favicon/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="./incl/img/favicon/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="./incl/img/favicon/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="./incl/img/favicon/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="./incl/img/favicon/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="./incl/img/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="./incl/img/favicon/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="./incl/img/favicon/favicon-16x16.png">
<meta name="msapplication-TileImage" content="./incl/img/favicon/ms-icon-144x144.png">
<meta name="msapplication-navbutton-color" content="#ccc">
<meta name="msapplication-TileColor" content="#ccc">
<meta name="apple-mobile-web-app-status-bar-style" content="#ccc">
<meta name="theme-color" content="#ccc">
<title>Barcode Buddy Screen</title>
<style>
body,
html {
padding: 0;
margin: 0;
position: relative;
height: 100%
}
.main-container {
height:100%;
display:flex;
display: -webkit-flex;
flex-direction: column;
-webkit-flex-direction: column;
-webkit-align-content: stretch;
align-content: stretch;
}
.header {
width: 100%;
background: #ccc;
padding: 10px;
box-sizing: border-box;
text-transform: lowercase;
flex: 0 1 auto;
}
.content {
background: #eee;
width: 100%;
padding: 10px;
flex: 1 0 auto;
box-sizing: border-box;
padding: 10px;
text-align: center;
align-content: center
}
.hdr-left {
text-align: center;
padding-left: 10px;
}
.hdr-right {
float: right;
width: 30%;
text-align: right;
padding-right: 10px
}
#soundbuttondiv {
position: fixed;
bottom: 10px;
right: 10px;
}
.h1 {
font: bold 4em arial;
margin: auto;
text-align: center;
}
.h2 {
font: bold 3em arial;
margin: auto;
padding: 10px;
text-align: center;
}
.h3 {
font: bold 2em arial;
margin: auto;
padding: 10px;
text-align: center;
}
.h4 {
font: bold 1.5em arial;
margin: auto;
padding: 6px;
}
.h5 {
font: bold 1em arial;
margin: auto;
text-align: center;
}
.sound {
background-color: #31B0D5;
color: white;
padding: 1em 2em;
border-radius: 4px;
border-color: #46b8da;
}
#muteimg {
height: 2em;
width: 2em;
}
@media only screen and (orientation: portrait) not (display-mode: fullscreen) {
.sound {
padding: 2em 4em;
}
#muteimg {
height: 3em;
width: 3em;
}
}
</style>
</head>
<body>
<script src="./incl/js/nosleep.min.js"></script>
<script src="./incl/js/he.js"></script>
<div class="main-container">
<div id="header" class="header">
<span class="hdr-right h4">
Status: <span id="grocy-sse">Connecting...</span><br>
</span>
<span id="mode" class="h1 hdr-left"></span>
</div>
<div id="content" class="content">
<p id="scan-result" class="h2">If you see this for more than a couple of seconds, please check if the websocket server has been started and is available</p>
<div id="log">
<p id="event" class="h3"></p><br>
<div id="previous-events">
<p class="h4 p-t10"> previous scans: </p>
<span id="log-entries" class="h5"></span>
</div>
</div>
</div>
</div>
<audio id="beep_success" muted="muted" src="incl/websocket/beep.ogg" type="audio/ogg" preload="auto"></audio>
<audio id="beep_nosuccess" muted="muted" src="incl/websocket/buzzer.ogg" type="audio/ogg" preload="auto"></audio>
<div id="soundbuttondiv">
<button class="sound" onclick="toggleSound()" id="soundbutton"><img id="muteimg" src="incl/img/mute.svg" alt="Toggle sound and wakelock"></button>
</div>
<script>
var noSleep = new NoSleep();
var wakeLockEnabled = false;
var isFirstStart = true;
function toggleSound() {
if (!wakeLockEnabled) {
noSleep.enable();
wakeLockEnabled = true;
document.getElementById('beep_success').muted=false;
document.getElementById('beep_nosuccess').muted=false;
<?php if (BBConfig::getInstance()["WS_FULLSCREEN"]) { echo " document.documentElement.requestFullscreen();"; }?>
document.getElementById("muteimg").src = "incl/img/unmute.svg";
} else {
noSleep.disable();
<?php if (BBConfig::getInstance()["WS_FULLSCREEN"]) { echo " document.exitFullscreen();"; } ?>
wakeLockEnabled = false;
document.getElementById('beep_success').muted=true;
document.getElementById('beep_nosuccess').muted=true;
document.getElementById("muteimg").src = "incl/img/mute.svg";
}
}
if(typeof(EventSource) !== "undefined") {
var source = new EventSource("incl/sse/sse_data.php");
var currentScanId = 0;
var connectFailCounter = 0;
source.addEventListener("error", function(event) {
switch (event.target.readyState) {
case EventSource.CONNECTING:
document.getElementById('grocy-sse').textContent = 'Reconnecting...';
// console.log('Reconnecting...');
connectFailCounter ++
if (connectFailCounter == 500) {
source.close();
document.getElementById('grocy-sse').textContent = 'Unavailable';
document.getElementById('scan-result').textContent = 'Sorry, the server is offline';
}
break;
case EventSource.CLOSED:
console.log('Connection failed (CLOSED)');
break;
}
}, false);
async function resetScan(scanId) {
await sleep(3000);
if (currentScanId == scanId) {
document.getElementById('content').style.backgroundColor = '#eee';
document.getElementById('scan-result').textContent = 'waiting for barcode...';
document.getElementById('event').textContent = '';
}
};
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
};
function resultScan(color, message, text, sound) {
document.getElementById('content').style.backgroundColor = color;
document.getElementById('event').textContent = message;
document.getElementById('scan-result').textContent = text;
document.getElementById(sound).play();
document.getElementById('log-entries').innerText = '\r\n' + text + document.getElementById('log-entries').innerText;
currentScanId++;
resetScan(currentScanId);
};
source.onopen = function() {
document.getElementById('grocy-sse').textContent = 'Connected';
if (isFirstStart) {
isFirstStart=false;
document.getElementById('scan-result').textContent = 'waiting for barcode...';
var http = new XMLHttpRequest();
http.open("GET", "incl/sse/sse_data.php?getState");
http.send();
}
};
source.onmessage = function(event) {
var resultJson = JSON.parse(event.data);
var resultCode = resultJson.data.substring(0, 1);
var resultText = resultJson.data.substring(1);
switch(resultCode) {
case '0':
resultScan("#33a532", "", he.decode(resultText), "beep_success");
break;
case '1':
resultScan("#a2ff9b", "Barcode Looked Up", he.decode(resultText), "beep_success");
break;
case '2':
resultScan("#eaff8a", "Unknown Barcode", resultText, "beep_nosuccess");
break;
case '4':
document.getElementById('mode').textContent = resultText;
break;
case 'E':
document.getElementById('content').style.backgroundColor = '#CC0605';
document.getElementById('grocy-sse').textContent = 'disconnected';
document.getElementById('scan-result').style.display = 'none'
document.getElementById('previous-events').style.display = 'none'
document.getElementById('event').setAttribute('style', 'white-space: pre;');
document.getElementById('event').textContent = "\r\n\r\n"+resultText;
break;
}
};
} else {
document.getElementById('content').style.backgroundColor = '#f9868b';
document.getElementById('grocy-sse').textContent = 'Disconnected';
document.getElementById('event').textContent = 'Sorry, your browser does not support server-sent events';
}
</script>
</body>
</html>