Spaces:
Runtime error
Runtime error
File size: 1,653 Bytes
423b87b 142f91b 70b8e47 423b87b 560b99e 6946674 66ed450 423b87b 70b8e47 6946674 70b8e47 5636b7a 423b87b 67cbe97 423b87b 70b8e47 6946674 70b8e47 423b87b 70b8e47 142f91b 423b87b 35946a9 |
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 |
<script context="module" lang="ts">
export const prerender = true;
</script>
<!--
The main code for this component is in src/PixelArtTogether.svelte
This file contains the Liveblocks providers, based on the
liveblocks-react library
https://liveblocks.io/docs/api-reference/liveblocks-react#LiveblocksProvider
-->
<script lang="ts">
import { onMount } from 'svelte';
import { createClient } from '@liveblocks/client';
import type { Client } from '@liveblocks/client';
import LiveblocksProvider from '$lib/liveblocks/LiveblocksProvider.svelte';
import RoomProvider from '$lib/liveblocks/RoomProvider.svelte';
import App from '$lib/App.svelte';
import type { PageData } from './$types';
import { PUBLIC_API_BASE } from '$env/static/public';
export let data: PageData;
let roomId: string;
let loaded = false;
let client: Client;
$: {
console.log('data changed', data);
}
onMount(() => {
document.addEventListener('wheel', (e) => e.preventDefault(), { passive: false });
// Add random id to room param if not set, and return the id string
// e.g. /?room=758df70b5e94c13289df6
roomId = 'sd-multiplayer-room-0';
// Connect to the authentication API for Liveblocks
client = createClient({
// publicApiKey: 'pk_test_JlUZGH3kQmhmZQiqU2l8eIi5'
authEndpoint: PUBLIC_API_BASE + '/auth'
});
loaded = true;
});
</script>
{#if loaded}
<!-- Provides Liveblocks hooks to children -->
<LiveblocksProvider {client}>
<!-- Create a room from id e.g. `sveltekit-pixel-art-758df70b5e94c13289df6` -->
<RoomProvider id={roomId}>
<!-- Main app component -->
<App />
</RoomProvider>
</LiveblocksProvider>
{/if}
|