So, i am trying to make a chat application but i am not recieving the realtime response and not even the error. I am give any permission to my collection to create, read, update and delete.
realTime(callback) {
console.log("Subscribing to real-time updates");
this.unsubscribeFn = this.client.subscribe(
// returns a function
databases.${conf.appwriteDatabaseId}.collections.${conf.appwriteCollectionId}.documents
,
(response) => {
if (response.error) {
console.error("Realtime error:", response.error);
} else {
callback(response);
}
},
);
}
ussage: useEffect(() => { const fetchdata = async () => { try { const response = await dbService.getPosts(); //promise dispatch(intialMsg(response.documents)); // array // console.log(response.documents); // console.log(ans); } catch (error) { console.log("error fetching"); } }; fetchdata();
const handleRealtimeUpdate = (res) => {
console.log("Real-time update received", res);
// Handle different types of events
if (res.events.includes("databases.*.collections.*.documents.*.create")) {
console.log("created");
dispatch(addMsg(res.payload));
} else if (
res.events.includes("databases.*.collections.*.documents.*.delete")
) {
console.log("deleted");
dispatch(rmMsg(res.payload.$id));
} else if (
res.events.includes("databases.*.collections.*.documents.*.update")
) {
console.log("update");
dispatch(updateMsg(res.payload));
}
};
dbService.realTime(handleRealtimeUpdate);
return () => {
dbService.unsubscribe(); // to stop double render
};
}, [dispatch]); // show messages after dom renders
useeffect code
Recommended threads
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...
- custom domain with CloudFlare
Hi all, it seems that CloudFlare has blocked cross-domain CNAME link which made my app hostname which is in CloudFlare, unable to create a CNAME pointing to clo...
- Custom emails
What happen if I use a third party email provider to customize my emails and my plan run out of emails/month? Appwrite emails are used as fallback sending emai...