-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
210 lines (162 loc) · 6.04 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
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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>QR code audio live reader</title>
<link type="text/css" rel="stylesheet" href="core/main.css">
</head>
<body data-has-audio="0" data-is-playing="0">
<div id="video-container">
<video id="qr-video"></video>
<div id="pulse"></div>
<div id="replay">
<div id="replay-button">
<svg width="44" height="44" fill="none" viewBox="0 0 44 44">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.753 17.56a12.019 12.019 0 0 1 5.738-6.259 12.098 12.098 0 0 1 8.46-.923 12.05 12.05 0 0 1 6.962 4.872 11.96 11.96 0 0 1-1.975 15.734A12.08 12.08 0 0 1 21.985 34a12.081 12.081 0 0 1-7.971-2.968 12.007 12.007 0 0 1-2.72-3.425M10 10.06v7.5h7.532" />
</svg>
</div>
</div>
<div id="play-pause">
<div id="play-button">
<svg width="44" height="44" fill="none" viewBox="0 0 44 44">
<path fill="currentColor" d="M34.209 20.294c1.275.78 1.275 2.633 0 3.412L14.543 35.728c-1.332.815-3.043-.144-3.043-1.706V9.978c0-1.562 1.71-2.52 3.043-1.706L34.21 20.294Z" />
</svg>
</div>
<div id="pause-button">
<svg width="44" height="44" fill="none" viewBox="0 0 44 44">
<path fill="currentColor" d="M15.5 9a1.5 1.5 0 0 0-1.5 1.5v23a1.5 1.5 0 0 0 3 0v-23A1.5 1.5 0 0 0 15.5 9Zm13 0a1.5 1.5 0 0 0-1.5 1.5v23a1.5 1.5 0 0 0 3 0v-23A1.5 1.5 0 0 0 28.5 9Z" />
</svg>
</div>
</div>
<div id="close">
<div id="close-button">
<svg width="44" height="44" fill="none" viewBox="0 0 44 44">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M33 11 11 33m0-22 22 22" />
</svg>
</div>
</div>
</div>
<script src="config.js"></script>
<script type="module">
import QrScanner from "./core/qr-scanner.min.js";
const body = document.body;
const video = document.getElementById('qr-video');
const videoContainer = document.getElementById('video-container');
const playPauseContainer = document.getElementById('play-pause');
const playButton = document.getElementById('play-button');
const pauseButton = document.getElementById('pause-button');
const replayContainer = document.getElementById('replay');
const replayButton = document.getElementById('replay-button');
const closeContainer = document.getElementById('close');
const closeButton = document.getElementById('close-button');
const pulse = document.getElementById('pulse');
let timeoutPulse = null;
let audio = null;
let previousCode = null;
if (config.enablePlayPause && config.enablePlayPause == true) {
playPauseContainer.classList.add('enabled');
}
if (config.enableReplay && config.enableReplay == true) {
replayContainer.classList.add('enabled');
}
if (config.enableClose && config.enableClose == true) {
closeContainer.classList.add('enabled');
}
// ####### Web Cam Scanning #######
const scanner = new QrScanner(video, result => onResult(result), {
onDecodeError: error => {
// console.log(error);
// camQrResult.textContent = error;
},
preferredCamera: config.camera,
highlightScanRegion: config.highlightScanRegion || false,
highlightCodeOutline: config.highlightQRCodeOutline || false,
});
scanner.start().then(() => {
scanner._updateOverlay();
});
// for debugging
window.scanner = scanner;
if (config.theme) {
const detections = {
'black-on-white': 'original',
'white-on-black': 'invert',
'both': 'both',
};
scanner.setInversionMode(detections[config.theme]);
}
function onResult(result) {
const code = result.data;
let newAudio = new Audio('sounds/' + code + '.mp3');
newAudio.onloadeddata = function () {
newAudio.onended = function () {
closeAudio();
};
// if new audio is different from previous audio
if (previousCode != code) {
clearTimeout(timeoutPulse);
pulse.classList.remove('animate');
setTimeout(function () {
pulse.classList.add('animate');
}, 1);
timeoutPulse = setTimeout(() => {
pulse.classList.remove('animate');
}, 1200);
if (audio !== null) {
pauseAudio();
}
audio = newAudio;
previousCode = code;
playAudio();
}
}
}
document.getElementById('play-button').addEventListener('click', () => {
if (audio !== null) {
playAudio()
}
});
document.getElementById('pause-button').addEventListener('click', () => {
if (audio !== null) {
pauseAudio();
}
});
document.getElementById('replay-button').addEventListener('click', () => {
if (audio !== null) {
replayAudio();
}
});
document.getElementById('close-button').addEventListener('click', () => {
if (audio !== null) {
closeAudio();
}
});
function playAudio() {
audio.play();
body.setAttribute('data-has-audio', 1);
body.setAttribute('data-is-playing', 1);
}
function pauseAudio() {
audio.pause();
body.setAttribute('data-has-audio', 1);
body.setAttribute('data-is-playing', 0);
}
function replayAudio() {
audio.currentTime = 0.00001;
audio.play();
body.setAttribute('data-has-audio', 1);
body.setAttribute('data-is-playing', 1);
}
function closeAudio() {
audio.pause();
audio = null;
previousCode = null; // allow scanning the same code again
body.setAttribute('data-has-audio', 0);
body.setAttribute('data-is-playing', 0);
}
</script>
</body>
</html>