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
- How to Display File in Web?
I'm trying to use Appwrite's Storage to store images and display them in my app, however when I use the `getFileView`, `getFileDownload` or `getFilePreview` met...
- Project Paused Despite Daily Active Usag...
I noticed that my project was automatically **paused**, even though it is actively being used. The project is an **attendance application** that is used daily b...
- Sudden CORS Errors - Domain hasn't Chang...
I have an Appwrite project with two web apps configured, the first one has the hostname `*` and the second one I just added to test if it could fix the issue wi...