-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
87 lines (84 loc) · 2.98 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
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="third_party/quiet-js/quiet.js"></script>
<script src="compress.js"></script>
<script src="serverless-webrtc.js"></script>
<script async type="text/javascript" src="third_party/quiet-js/quiet-emscripten.js"></script>
<script>
window.dc = null;
window.ctx = null;
document.addEventListener('DOMContentLoaded', () => {
initCanvas();
document.getElementById('profile').addEventListener('change', () => {
QUIET_PROFILE = document.getElementById('profile').selectedOptions[0].value;
console.log('changed to profile ' + QUIET_PROFILE);
});
document.getElementById('offer').addEventListener('click', async () => {
let dc = await connect();
onconnect(dc);
});
document.getElementById('accept').addEventListener('click', async () => {
let dc = await accept();
onconnect(dc);
});
});
function onconnect(dc) {
window.dc = dc;
console.log('Connected!');
dc.addEventListener('message', (evt) => {
console.log('Received: ' + evt.data);
try {
let parsed = JSON.parse(evt.data);
if (parsed.draw)
draw(parsed.draw[0], parsed.draw[1]);
} catch (e) {}
});
}
const RADIUS = 10;
function draw(x, y, local) {
ctx.fillStyle = 'rgba(0, 175, 0, 0.5)';
ctx.beginPath();
ctx.arc(x, y, RADIUS, 0, 2 * Math.PI);
ctx.fill();
if (local && dc)
dc.send(JSON.stringify({draw: [x, y]}));
}
function initCanvas() {
let canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
canvas.addEventListener('touchstart', (evt) => {
evt.preventDefault();
});
canvas.addEventListener('touchmove', (evt) => {
for (let i = 0; i < evt.touches.length; i++) {
draw(evt.touches[i].clientX + document.scrollingElement.scrollLeft - canvas.offsetLeft, evt.touches[i].clientY + document.scrollingElement.scrollTop - canvas.offsetTop, true);
}
evt.preventDefault();
});
}
</script>
<style>
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<select id="profile">
<option>audible</option>
<option>audible-7k-channel-0</option>
<option>audible-7k-channel-1</option>
<option>cable-64k</option>
<option>hello-world</option>
<option>ultrasonic</option>
<option>ultrasonic-3600</option>
<option>ultrasonic-whisper</option>
<option>ultrasonic-experimental</option>
</select>
<button id="accept">Accept connection</button><button id="offer">Make connection</button>
<p>Watch the console - all the interesting stuff happens there.</p>
<canvas id="canvas" width="400" height="400"></canvas>
</body>
</html>