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
- Request for JWKS Endpoint and OIDC Disco...
Hey Appwrite Team, Do you have plans to support JWKS and a well-known OIDC discovery endpoint? This would let us verify Appwrite JWTs in other services using st...
- Sites are not opening
my all sites are not opening so plz check what is the issue, when i am opening the sites showing an error like, Access to XMLHttpRequest at 'https://cloud.appw...
- unable to create project with custom id
when creating a project, and click on project ID button, nothing happens. is this a bug?