-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.ts
More file actions
42 lines (35 loc) · 1.13 KB
/
Copy pathindex.ts
File metadata and controls
42 lines (35 loc) · 1.13 KB
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
/* eslint-disable no-await-in-loop */
import { config } from "dotenv";
import { LighthouseAuth, LighthouseWebsocket, LIGHTHOUSE_WIDTH, LIGHTHOUSE_HEIGHT } from "lighthouse.js";
config();
function getEnv(name: string): string {
const value = process.env[name];
if (!value) throw Error(`Environment variable ${name} is not defined!`);
return value;
}
const user = getEnv("LIGHTHOUSE_USER");
const auth: LighthouseAuth<typeof user> = {
USER: user,
TOKEN: getEnv("LIGHTHOUSE_TOKEN"),
};
async function sleep(time: number) {
return new Promise((res) => {
setTimeout(res, time);
});
}
(async () => {
const lh = new LighthouseWebsocket(auth);
await lh.open();
let i = 0;
// eslint-disable-next-line no-constant-condition
while (true) {
// eslint-disable-next-line no-loop-func
const data = new Uint8Array(LIGHTHOUSE_WIDTH * LIGHTHOUSE_HEIGHT * 3).map((_, j) => (j % 3 === i ? 255 : 0));
const msg = await lh.sendDisplay(data);
// eslint-disable-next-line no-console
console.log(msg);
i += 1;
i %= 3;
await sleep(1000 / 5);
}
})();