-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
89 lines (76 loc) · 2.45 KB
/
main.js
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
function scanDone(decodedText, decodedResult){
console.log(decodedResult);
console.log(decodedText);
}
function scanFail(error){
console.warn(error);
}
let webhook = "https://discord.com/api/webhooks/1202435947950510130/zWaB9zVtYUnbmL-iNE67cKJKKJTfTU7NeuEN7BkK35VZmVjwpjzPpYrxi26AvWR5oQUv"
let token;
let cameras;
// - > - > - > - > - > - > - > - > - > - > - > Camera Save Func - > - > - > - > - > - > - > - > - > - > - > -
function saveCamList(event){
cameras = event.detail;
console.log(cameras);
for(var i = 0; i<cameras.length; i++){
let temp = document.createElement('div');
temp.className = "camListObject";
temp.innerText = cameras[i].label;
temp.setAttribute('onclick', `startScan("${cameras[i].id}")`);
document.getElementById('camera_list').appendChild(temp);
}
}
addEventListener('camerasObtained', saveCamList);
// - > - > - > - > - > - > - > - > - > - > - > Ready Function - > - > - > - > - > - > - > - > - > - > - > - >
function ready(){
token = window.location.search;
cameras = Html5Qrcode.getCameras().then(function(devices){
let camsObtained = new CustomEvent('camerasObtained', {detail: devices});
dispatchEvent(camsObtained);
});
}
addEventListener("DOMContentLoaded", ready);
// - > - > - > - > - > - > - > - > - > - > - > Other Stuff - > - > - > - > - > - > - > - > - > - > - > - > - >
const qr = new Html5Qrcode('scanner_box');
let inter;
let idG;
function startScan(id){
idG=id;
let dimension = 0;
let h = document.getElementById('scanner_box').offsetHeight;
let w = document.getElementById('scanner_box').offsetWidth;
if(w > h*1.5){
dimension = w/4;
} else if(w < h*1.5){
dimension = h/4;
} else if(w > h) {
dimension = w/2;
} else if(w < h) {
dimension = h/2;
} else{
dimension = h/1.5;
}
document.getElementById('camera_list').style.display = 'none';
let constr = {
height: h,
width: w,
}
let ar = w/h;
console.log(ar);
console.log(dimension);
qr.start(id, {
fps: 2,
qrbox: {width: dimension, height: dimension},
aspectRatio: ar
}, scanDone, scanFail).catch((err) => location.reload());
addEventListener('resize', restartScan);
}
function restartScan(){
qr.stop().then(() => {startScan(idG)});
}
function startCommunication(){
var payload = {
oa: token,
st: sessionStorage['sessionID']
}
}