forked from HarishGangula/quizServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.html
189 lines (176 loc) · 5.55 KB
/
quiz.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
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="bootstrap.min.css" />
<script src="jsQR.js"></script>
<script src="jquery.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="jquery-1.10.2.js"></script>
<script src="lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fingerprintjs2/2.0.6/fingerprint2.min.js"></script>
<style>
.login-container {
width: 500px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.5);
border-radius: 5px;
}
.login-container .title h2 {
font-size: 26px;
}
.login-container input {
border: 1px solid #d2d0d0;
}
</style>
</head>
<body>
<div class="login-container p-3">
<div class="title pb-3"><h2>Devcon Login</h2></div>
<div class="login-body">
<canvas style="width: 100%;" id="canvas"></canvas>
<input
name="input-QR"
id="qrcode"
class="w-100 my-3 py-2"
style="display: none;"
/>
</div>
</div>
<script>
var deviceId;
Fingerprint2.getV18(did => {
deviceId = did;
});
var video = document.createElement("video");
var canvasElement = document.getElementById("canvas");
var canvas = canvasElement.getContext("2d");
function drawLine(begin, end, color) {
canvas.beginPath();
canvas.moveTo(begin.x, begin.y);
canvas.lineTo(end.x, end.y);
canvas.lineWidth = 4;
canvas.strokeStyle = color;
canvas.stroke();
}
// Use facingMode: environment to attemt to get the front camera on phones
navigator.mediaDevices
.getUserMedia({ video: { facingMode: "environment" } })
.then(function(stream) {
video.srcObject = stream;
video.setAttribute("playsinline", true); // required to tell iOS safari we don't want fullscreen
video.play();
requestAnimationFrame(tick);
});
function tick() {
if (video.readyState === video.HAVE_ENOUGH_DATA) {
canvasElement.height = video.videoHeight;
canvasElement.width = video.videoWidth;
canvas.drawImage(
video,
0,
0,
canvasElement.width,
canvasElement.height
);
var imageData = canvas.getImageData(
0,
0,
canvasElement.width,
canvasElement.height
);
var code = jsQR(imageData.data, imageData.width, imageData.height);
if (code && !document.getElementById("qrcode").value) {
drawLine(
code.location.topLeftCorner,
code.location.topRightCorner,
"#FF3B58"
);
drawLine(
code.location.topRightCorner,
code.location.bottomRightCorner,
"#FF3B58"
);
drawLine(
code.location.bottomRightCorner,
code.location.bottomLeftCorner,
"#FF3B58"
);
drawLine(
code.location.bottomLeftCorner,
code.location.topLeftCorner,
"#FF3B58"
);
document.getElementById("qrcode").value = code.data;
verifyQrCode(code.data);
}
}
requestAnimationFrame(tick);
}
function verifyQrCode(code) {
// Add your stall data
var data = {
request: {
code: code,
stallCode: "STA2",
ideaCode: "IDE7"
}
};
// Add your stall telemetry data and remove unwanted telemetry
$.ajax({
async: true,
crossDomain: true,
method: "POST",
url: "https://dev.ekstep.in/api/devcon/v3/login",
data: JSON.stringify(data),
contentType: "application/json"
})
.done(function(data) {
if (data.result && data.result.Visitor) {
window.sessionStorage.setItem(
"user",
JSON.stringify(data.result.Visitor)
);
var telemetryData = {
events: [
{
eid: "DC_START",
ets: new Date().getTime(),
did: deviceId,
dimensions: {
visitorId: code,
stallId: "STA2",
ideaId: "IDE7",
visitorName: _.get(data, "result.Visitor.name"),
stallName: "Classroom",
ideaName: "Multiplayer Quiz",
school: _.get(data, "result.Visitor.school"),
district: _.get(data, "result.Visitor.district")
},
edata: {}
}
]
};
$.ajax({
async: true,
crossDomain: true,
method: "POST",
url: "/telemetry",
data: JSON.stringify(telemetryData),
dataType: "json",
contentType: "application/json"
}).done(function(data) {
console.log(data);
window.location.replace("/player.html");
});
} else {
}
})
.error(function(error) {});
}
</script>
</body>
</html>