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.
The
awaitActivity
function returned byuseInbox
anduseOutbox
(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 byuseCollection
. 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 callsawaitWebSocketConnection
first, wait for the webSocket connection to be ready, and then start watching for activities using the webSocket ref that was returned.