-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.js
48 lines (48 loc) · 1.66 KB
/
client.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
const id = (eid) => {
return document.getElementById(eid);
};
id("startmirror").onclick = async () => {
id("card-body").innerText = "Connecting to calculator...";
let api = new TIWebConnApi();
let scr = document.createElement("script");
scr.src = "tiusb-1.js";
document.body.appendChild(scr);
await new Promise(async (resolveall) => {
await new Promise((resolve) => {
scr.onload = async () => {
await api.init(resolveall, console.log, console.log, console.log, console.log);
resolve();
};
});
await api.getDevices();
});
console.log(await api.getDeviceInfo());
window.tiapi = api;
const setCtxToScreen = async (ctx) => {
let screendata = await api.getScreen();
let imagedata = new ImageData(320, 240);
imagedata.data.set(screendata, 0);
ctx.putImageData(imagedata, 0, 0);
};
let canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 240;
id("card-body").innerText = "";
id("card-body").appendChild(canvas);
let mirror = async () => {
await setCtxToScreen(canvas.getContext("2d"));
window.requestAnimationFrame(mirror);
};
mirror();
id("card-body").appendChild(document.createElement("br"));
let btnFullscreen = document.createElement("button");
btnFullscreen.innerText = "Full Screen";
btnFullscreen.classList.add("btn", "btn-primary");
btnFullscreen.onclick = () => {
canvas.requestFullscreen();
canvas.onclick = () => {
document.exitFullscreen();
};
};
id("card-body").appendChild(btnFullscreen);
};