/
index.jsx
53 lines (42 loc) · 1.38 KB
/
index.jsx
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
/* @refresh reload */
import { render } from "solid-js/web";
import { createClient } from "@liveblocks/client";
import App from "./App";
import "./index.css";
let PUBLIC_KEY = "pk_YOUR_PUBLIC_KEY";
let roomId = "solidjs-live-cursors";
applyExampleRoomIdAndApiKey();
if (!/^pk_/.test(PUBLIC_KEY)) {
console.warn(
`Replace "${PUBLIC_KEY}" by your public key from https://liveblocks.io/dashboard/apikeys.\n` +
`Learn more: https://github.com/liveblocks/liveblocks/tree/main/examples/solidjs-live-cursors#getting-started.`
);
}
const client = createClient({
publicApiKey: PUBLIC_KEY,
});
const initialPresence = {
cursor: null,
};
// If you no longer need the room (for example when you unmount your
// component), make sure to call leave()
const { room, leave } = client.enterRoom(roomId, { initialPresence });
render(() => <App room={room} />, document.getElementById("root"));
/**
* This function is used when deploying an example on liveblocks.io.
* You can ignore it completely if you run the example locally.
*/
function applyExampleRoomIdAndApiKey() {
if (typeof window === "undefined") {
return;
}
const query = new URLSearchParams(window?.location?.search);
const exampleId = query.get("exampleId");
const apiKey = query.get("apiKey");
if (exampleId) {
roomId = exampleId ? `${roomId}-${exampleId}` : roomId;
}
if (apiKey) {
PUBLIC_KEY = apiKey;
}
}