Spaces:
Runtime error
Runtime error
File size: 974 Bytes
1d701d3 66ed450 70b8e47 142f91b 70b8e47 66ed450 1d701d3 |
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 |
import { writable, get } from 'svelte/store';
import type { Room } from '@liveblocks/client';
import { type ZoomTransform, zoomIdentity } from 'd3-zoom';
export const loadingState = writable<string>('');
export const isLoading = writable<boolean>(false);
export const currZoomTransform = writable<ZoomTransform>(zoomIdentity);
export const myPresence = writable(null);
export const others = writable(null);
export function createPresenceStore(room: Room) {
// Get initial values for presence and others
myPresence.set(room.getPresence());
others.set(room.getOthers());
const unsubscribeMyPresence = room.subscribe('my-presence', (presence) => {
myPresence.update((_) => presence);
});
const unsubscribeOthers = room.subscribe('others', (otherUsers) => {
others.update((_) => otherUsers);
});
myPresence.set = (presence) => {
room.updatePresence(presence);
return presence;
};
return () => {
unsubscribeMyPresence();
unsubscribeOthers();
};
}
|