-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
41 lines (36 loc) · 1.01 KB
/
main.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
import App from "./src/client/twitch-alerts/App.svelte";
import {
ClientDataStore,
makeClientDataStore,
} from "./src/client/twitch-alerts/ClientDataStore";
import { DataEvent } from "./src/client/twitch-alerts/Events";
const clientDataStore = makeClientDataStore();
const socket = new WebSocket(import.meta.env.VITE_WEBSOCKET_URL);
socket.addEventListener("open", () => {
console.log("connected");
});
socket.addEventListener("message", (event) => {
const message: DataEvent = JSON.parse(event.data);
const oldData = clientDataStore.get();
if (message.type === "userMessage") {
clientDataStore.set({
...oldData,
lastUser: message.data,
});
} else if (message.type === "alert") {
clientDataStore.set({
...oldData,
alerts: oldData.alerts.concat({
key: Math.random(),
...message.data,
}),
});
}
});
const app = new App({
target: document.body,
props: {
debug: !window.location.search.includes("twitch=1"),
dataStore: clientDataStore,
},
});