Skip to content

Commit

Permalink
Add presence tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniils Petrovs committed Jun 27, 2024
1 parent 1801f2b commit dd8983a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import { setToast } from '$lib/stores/toasts';
import { get } from 'svelte/store';
import { TOAST_TYPE } from '../custom';
import { updateExpectedStamps } from '../stamps';
import { supabase } from '../supabase-client';

export const load = (async () => {
setupPresence();
await startupTasks();

return {};
}) satisfies LayoutLoad;

Expand All @@ -25,3 +28,20 @@ async function startupTasks() {
}
setToast({ message: 'Updated stamp data', type: TOAST_TYPE.SUCCESS });
}

function setupPresence() {
const globalRoom = supabase.channel('room:global');

globalRoom
.on('presence', { event: 'sync' }, () => {
const newState = globalRoom.presenceState();
console.log('sync', newState);
})
.on('presence', { event: 'join' }, ({ key, newPresences }) => {
console.log('join', key, newPresences);
})
.on('presence', { event: 'leave' }, ({ key, leftPresences }) => {
console.log('leave', key, leftPresences);
})
.subscribe();
}

0 comments on commit dd8983a

Please sign in to comment.