File size: 754 Bytes
bb88c4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!--
  Works similarly to `liveblocks-react` RoomProvider
  https://liveblocks.io/docs/api-reference/liveblocks-react#RoomProvider
-->
<script lang="ts">
	// @ts-nocheck
	import { clientSymbol, roomSymbol } from './symbols';
	import type { Client, Room } from '@liveblocks/client';
	import { getContext, onDestroy, setContext } from 'svelte';
	import type { Presence } from '$lib/types';

	export let id: string;
	export let initialPresence: Presence = {};

	if (!id) {
		throw new Error('RoomProvider requires an id');
	}

	const client = getContext<Client>(clientSymbol);

	if (client) {
		const room = client.enter(id, { initialPresence });

		setContext<Room>(roomSymbol, room);

		onDestroy(() => {
			client.leave(id);
		});
	}
</script>

<slot />