How do I listen for a connection event with y-websocket on my server before my server 'knows' what my roomName and yDoc are?

Using socket.io, I can listen for a “roomless” connection event on the server and then create a new socket instance that has the relevant room data, e.g.

io.on(‘connection’), socket => {
socket.on(‘join-room’, (roomData) => {
socket.join(roomData);
}
}

But with y-websocket, I can’t seem to figure out how to pass the room data (and the yDoc data) through a y-websocket from the client side to the server before the server knows about the room data. It seems as if my server and my client must both know about the roomData before a y-websocket connection can be established at all.

I suppose I could do a regular POST request to create the y-websocket server instance with the yDoc and the roomData…but this feels more complicated.

Is there some way to listen for a connection on the server without pre-specifying the room data and ydoc?

I now think I need to use this in Node to “listen” for connections that will pass room data and yDoc data, which in turn I can use to create a y-websocket instance: this ws - npm

If anyone thinks I’m on the wrong track here, let me know. Thanks again!

y-websocket uses a single websocket connection per-room. That is intended as it provides several benefits. E.g. we can authenticate a connection to a room before transforming the HTTP handshake to a WebsocketConnection.

You are free to extend the functionality (e.g. by extending y-protocols to support multiple rooms per connection). However, I think you are really looking to build your own provider using socket.io.