yjs / y-websocket

Websocket Connector for Yjs
https://docs.yjs.dev/ecosystem/connection-provider/y-websocket
MIT License
523 stars 261 forks source link

Disconnect on Auth Failure: #87

Closed asalem1 closed 2 years ago

asalem1 commented 2 years ago

This is related to the thread here:

https://github.com/yjs/y-websocket/issues/7

Is your feature request related to a problem? Please describe. Currently emitting a message to trigger the message handler for unauthenticated requests continues reconnect attempts, despite getting console.warns according to the authProtocols here:

https://github.com/yjs/y-websocket/blob/master/src/y-websocket.js#L52-L54

Describe the solution you'd like As far as I can tell, there are two ways the API can stop reconnect attempts from the API:

  1. Explicitly close and NOT reconnect the websocket when a message this condition is hit.
  2. Have the websocket close the connection on the server, and handle that case on the onclose function on the websocket provider as suggested by the comment here

Describe alternatives you've considered An alternative might be to export the messageHandlers so that the user has more control on websocket connections handle them on an as needed basis

Additional context Unless I'm missing something, it seems like the websocket will continuously try to connect to the API despite receiving the unauthenticated request

asalem1 commented 2 years ago

@dmonad any thoughts on this? I'd love to make some headway on this but would wanna wait for your thoughts on how to go about it

asalem1 commented 2 years ago

Closing this, ended up resolving the issue by having the server send a specific auth code to listen for on the client. On the client, the y-websocket instance was listening for connection-close, where the code is returned and can just trigger a disconnect