-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.ts
51 lines (39 loc) · 1.34 KB
/
index.ts
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
import { SpiritBoard } from "./js/SpiritBoard";
import { JoinBox } from "./js/JoinBox";
import { Networking } from "./js/Networking";
import { AudioManager } from "./js/audio/AudioManager";
import { ConfigurationRepository } from "./js/ConfigurationRepository";
import { wait } from "./js/util"
(async function () {
const settings = new ConfigurationRepository();
const boardName = new URLSearchParams(location.search).get('boardName');
if (!boardName) {
const joinBox = new JoinBox("join", settings);
joinBox.setBoardName("spoopy-kids");
joinBox.show();
return;
}
const networking = new Networking();
const audioManager = new AudioManager(settings.load());
const board = new SpiritBoard("activeBoard", networking);
networking.on("join", () => {
board.planchette.centre();
});
networking.on("snap", (message) => {
board.planchette.snapTo(message.data);
});
networking.on("nudge", (message) => {
board.movePlanchette({ deltaX: message.data.deltaX, deltaY: message.data.deltaY });
});
await networking.connect(boardName);
board.onReveal(async (item) => {
board.spookyAnimate(item.text);
await wait(1_000);
audioManager.voiceItem(item);
});
board.show();
audioManager.playAmbientAudio();
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js');
}
})();