-
Notifications
You must be signed in to change notification settings - Fork 0
/
qr.html
41 lines (34 loc) · 992 Bytes
/
qr.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
<h1>Start Pairing</h1>
<form action="#">
</form>
<canvas id="canvas"></canvas>
<script src="js/qrcode.min.js"></script>
<script>
var ALPHABET = '0123456789abcdef';
var TOKEN_LENGTH = 5;
function generateToken() {
var token = '';
var count = 0;
var char;
var lastChar;
while (count < TOKEN_LENGTH) {
// Generate a random value from the alphabet.
var index = Math.floor(Math.random() * ALPHABET.length);
char = ALPHABET[index];
if (char != lastChar) {
count += 1;
token += char;
lastChar = char;
}
}
return token;
}
var token2 = generateToken();
QRCode.toCanvas(document.getElementById('canvas'), 'https://tawfiq-embross.github.io/send_pair.html?tok='+token2, function (error) {
if (error) console.error(error)
console.log(token2);
console.log('https://tawfiq-embross.github.io/listen_pair.html?tok='+token2);
})
// TODO: Send the token to the other device too.
// When user submits the form, send a message.
</script>