I'm receiving this error when attempting to setup a realtime connection listening for updates to a specific document in my users connection.
My code is as follows:
export async function addUserUpdateListener(auth_id: string, callback: (payload: RealtimeResponseEvent<unknown>) => void) {
try {
const userData = await db.listDocuments(
'chat',
'users',
[
// @ts-ignore
q.equal('auth_id', [auth_id])
]
);
if (userData.documents.length > 0) {
const [user] = userData.documents;
const {$id: userDocId} = user;
const event = `databases.chat.collections.users.documents.${userDocId}.update`;
return client.subscribe(event, callback);
}
}
catch (e) {
console.warn(e);
}
return null;
}
And the path it's attempting to open a websocket connection to is:
wss://cloud.appwrite.io/v1/realtime?project=648a2161cc4d4565adc2&channels%5B%5D=databases.chat.collections.messages.documents&channels%5B%5D=databases.chat.collections.users.documents.648a2228362b7d35edd2.update
Note it appears to be amalgamating the two realtime listeners I have, but I assume this is how it's meant to function.
It's also worth noting that the other realtime listener I have setup is still working.
Channels are a bit different from events, https://appwrite.io/docs/realtime#channels
To subscribe to channel that includes the update event you need to do something like this
const event = `databases.chat.collections.users.documents.${userDocId}`;
return client.subscribe(event, callback);
Awesome gotcha! Thanks @Binyamin 😄
[Solved] WebSocket is closed before the connection is established?
Recommended threads
- A resource limit has been exceeded for t...
Hi. My website has been blocked for exceeding the limit, and out of the 5GB I only used 1.18MB, while the email says 6.36GB. Project Id: 6908f95b002d8ad8d320
- Can I create a transaction that involves...
i want to create a row un `auth.users` and then create a user in a table `profiles` but i want to use the same id for both tables. So, if insert a row in pro...
- How do i connect to realtime? I dont get...
I am trying to connect to realtime database updates but don't seem to receive any updates. Documentation is pretty bad and i am stuck. Can anyone help? Here is ...