Search code examples
appwrite

appwrite realtime event handler never triggered


I'm trying some basic example with appwrite self-hosted using a react component as client. I'm not able to get realtime events. From network panel, websoket's tab in chrome, I'm able to see only the initial messages

{"type":"connected","data":{"channels":["databases.test.collections.*.documents"],"user":null}}

But then, changing something in any documents in any collections in 'test' database I'm not getting any other message.

Here is the react component I'm using:

const [events, setEvents] = useState([]);
const {appwriteEnv} = props;

useEffect(async() => {
    
    const client = await new Client()
        .setEndpoint(appwriteEnv.endpoint) 
        .setProject(appwriteEnv.projectID);

    const unsubscribe = client?.subscribe("databases.test.collections.*.documents", response => {            
            setEvents([response.payload, ...events]);
        }
    );

    return () => {
        unsubscribe ? unsubscribe() : null
    }
}, [appwriteEnv])

return <>
    <pre>{JSON.stringify(events, null, 2)}</pre>
</>;

I tried to edit, add, delete documents in test databases, any collection, but I'm not getting messages from websocket. All collections has persmission Any for read.


Solution

  • Wildcards are not supported for realtime channels. You should probably use documents instead.

    See the Appwrite docs for more details on supported channels.