-
Notifications
You must be signed in to change notification settings - Fork 9
/
App.tsx
36 lines (31 loc) · 1.15 KB
/
App.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
import { useSync } from '@tldraw/sync'
import { Tldraw } from 'tldraw'
import { getBookmarkPreview } from './getBookmarkPreview'
import { multiplayerAssetStore } from './multiplayerAssetStore'
// Where is our worker located? Configure this in `vite.config.ts`
const WORKER_URL = process.env.TLDRAW_WORKER_URL
// In this example, the room ID is hard-coded. You can set this however you like though.
const roomId = 'test-room'
function App() {
// Create a store connected to multiplayer.
const store = useSync({
// We need to know the websockets URI...
uri: `${WORKER_URL}/connect/${roomId}`,
// ...and how to handle static assets like images & videos
assets: multiplayerAssetStore,
})
return (
<div style={{ position: 'fixed', inset: 0 }}>
<Tldraw
// we can pass the connected store into the Tldraw component which will handle
// loading states & enable multiplayer UX like cursors & a presence menu
store={store}
onMount={(editor) => {
// when the editor is ready, we need to register our bookmark unfurling service
editor.registerExternalAssetHandler('url', getBookmarkPreview)
}}
/>
</div>
)
}
export default App