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
- How to cron function with specified end ...
I have function built with hono. support like / , /data, /data/2222. I want to schedule triggger for specific event like /data. orrr event better /data/2222 . i...
- 401 Access to this resource is blocked.
I was adding a large number of attributes to my collection and I started getting this error
- Help Needed: Appwrite Email Verification...
Help Needed: Appwrite Email Verification Error ```bash '$collectionId': 'users' Error in register function: AppwriteException: app.67188ef30017689a30d2@service....