-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
58 lines (48 loc) · 1.78 KB
/
index.tsx
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
import * as React from "react";
import { createRoot } from "react-dom/client";
import { LiveMap, LiveObject, createClient } from "@liveblocks/client";
import { ProjectStore } from "./src/project";
import { ElementId, FileFormat } from "./src/fileFormat";
import { App } from "./src/ui/app";
import { generateKeyBetween } from "fractional-indexing";
import { useAppState } from "./src/global";
import { Editor } from "./src/editor";
import { ElementRelations } from "./src/elementRelations";
async function init() {
const client = createClient({
// Rudi's personal account key, whatever if it gets leaked.
publicApiKey: "pk_dev_bz-E8idsnxtmBvO1Ag2vEJMfyCONfM1jcD7p7QfLtaXUHUaG3eUE-R13-8slYn3t"
});
const urlParams = new URLSearchParams(window.location.search);
const roomName = urlParams.get("room") ?? crypto.randomUUID();
urlParams.set("room", roomName);
history.replaceState(null, "", "?" + urlParams.toString());
console.log(`Entering room "${roomName}"`);
const levelId = crypto.randomUUID() as ElementId;
const { room, leave } = client.enterRoom(roomName, {
initialStorage: {
name: roomName,
elements: new LiveMap([
[levelId, new LiveObject({
type: "level",
id: levelId,
parentId: null,
parentIndex: generateKeyBetween(null, null),
} satisfies FileFormat.Level)],
]),
elementRelations: new LiveMap(),
}
});
const { root } = await room.getStorage();
console.log(`Entered.`);
const editor = new Editor(room, root as any);
const onFrame = () => {
editor.onFrame();
requestAnimationFrame(onFrame)
}
requestAnimationFrame(onFrame);
useAppState.setState({ room, editor });
const reactRoot = createRoot(document.getElementById("root")!);
reactRoot.render(<App />)
}
init();