Spaces:
Runtime error
Runtime error
File size: 1,545 Bytes
809d458 1d701d3 66ed450 70b8e47 142f91b a6e7e8f aa3e783 13a8b2e 70b8e47 66ed450 1d701d3 73e6846 1d701d3 73e6846 7cb7420 73e6846 |
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 |
import { writable } 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 isPrompting = writable<boolean>(false);
export const clickedPosition = writable<{ x: number; y: number }>();
export const showFrames = writable<boolean>(false);
export const text2img = writable<boolean>(false);
export const currZoomTransform = writable<ZoomTransform>(zoomIdentity);
export const myPresence = writable(null);
export const others = writable(null);
export const imagesList = 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();
};
}
export async function createStorageStore(room: Room) {
try {
const { root } = await room.getStorage();
const _imagesList = root.get('imagesList');
imagesList.set(_imagesList);
room.subscribe(_imagesList, () => {
imagesList.update((_) => _imagesList);
});
} catch (e) {
console.log(e);
}
}
|