so i'm testing a chat app feature that i'm making and i'm trying to chat between two accounds on different devices connected to the local development server but i have to refresh to see a new message that i type on my other device
here is my realtime subscription snippet
let unsubscribe;
const setupRealtimeConnection = () => {
return client.subscribe(
[
databases.${import.meta.env.VITE_DATABASE_COMMUNITIES_ID}.collections.${
import.meta.env.VITE_COLLECTION_ID_SERVER_MESSAGES
}.documents
],
(response) => {
const { events, payload } = response;
console.log(response);
scrollToBottom();
if (payload.communityId !== id) return;
if (events.includes('databases.*.collections.*.documents.create')) {
messages.update((msgs) => {
return [...msgs, payload].sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp));
});
}
}
);
};
onMount(async () => {
await listCommunities();
unsubscribe = setupRealtimeConnection();
scrollToBottom(); // Ensure scrolling is handled properly
getData(); // Fetch initial data
});
onDestroy(() => {
if (unsubscribe) unsubscribe(); // Clean up the subscription on component destroy
});
Recommended threads
- Charged after Downgrade
I downgraded from the pro plan last month, but it’s still trying to charge my card this month and my account has been restricted
- Sydney Cloud Sites: App Git deployment a...
Project ID: rentwize-db The app Site fails after the build completes with a missing build archive error. Site id: app Framework: TanStack Start SSR Output dir...
- Active Running Project Deletion Alert Em...
Hi , I received an email alert from Appwrite today stating “your project will be deleted within 14 days if no action is taken,” though I have been actively usin...