[y-websocket] Is there an event to identify that data has been uploaded to the server?

My scenario: create a document locally, input some content, and then establish a connection through y-websocket to upload it to the server.

The question is: when to close this connection(wsProvider)?

I currently use setTimeout to destroy the wsProvider after 5 seconds. But I don’t think it’s elegant.

Hi, @dmonad , I’m very sorry for the question issue I just posted on GitHub, which caused you a waste of extra energy. Next time I will give priority to posting relevant topics on the community forum. :handshake:

Hi @jarone,

It’s all good @jarone. That happens.

So you want to initialize a document on the client-side and make sure that it is synced to the server?

Currently, there is no mechanism to show the client how many updates (or which updates…) have been processed by the server. So you never really know…

I think the best solution would be to implement a separate HTTP PUT endpoint that accepts an encoded Yjs document and initializes a document (e.g. by storing it in the database and applying it to the local Yjs document, if there is any). Once the HTTP endpoint resolves, you know that the document has been stored.

However, I believe that only the server should initialize content. This avoids many problematic scenarios (e.g. two clients initializing at the same time). Ideally, you send the “initial document” to the server; the server will initialize it only if it doesn’t exist yet.

1 Like

Thank you for your suggestion. I believe this is the best and correct solution.