assemblee-virtuelle / semapps

A toolbox to create semantic web applications
https://semapps.org
Apache License 2.0
88 stars 9 forks source link

useCollection: new awaitWebSocketConnection method #1301

Closed srosset81 closed 3 months ago

srosset81 commented 3 months ago

The awaitActivity function returned by useInbox and useOutbox (see https://github.com/assemblee-virtuelle/semapps/pull/1295) was not usable, because in many cases the webSocket connection was not ready when we started listening (it takes half a second to be established with the server).

So I first used React's useRef to create a permanent reference to the webSocket. This way it does not depend on states or dependencies.

Then I created a new method awaitWebSocketConnection that is now returned by useCollection. As its name implies, this method wait for the webSocket connection to be established, and then return the webSocket ref. A timeout can be set, which defaults to 30s.

The awaitActivity function now calls awaitWebSocketConnection first, wait for the webSocket connection to be ready, and then start watching for activities using the webSocket ref that was returned.