
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
- I am trying to run appwrite storage list...
Hello! I am trying to use a command to return all of my files from my bucket. This is the cmd I am currently running: "appwrite storage list-files --bucket-id <...
- nextjs site template gets 500 for /v1/pi...
whats the right way to configure this? do i need to deploy a function? im loosing my hair and i can't get a nextjs site to work. pls help
- WebSocket connection failed - Realtime g...
I am using appwrite cloud + angular (appwrite 21.2.1). On Chrome, when I have a realtime subscribtion and I reload the page or navigate to another page, realtim...
