Server-side initial awareness info

Hi! I was wondering if anyone has an example where the server sets the userDescription, instead of the user/client. We’d like the server to be in control of this information.

I’m trying to piece all the pieces together, but was wondering if anyone has some code lying somewhere that already shows this :slight_smile:

I’ve managed to do this, in a way. I pass the current clientID from the client to the server when connecting to websockets. I use this clientID to set an awareness state on the server and I also start the server-side clock at 1, so that it gets accepted by clients. And then that sort of works :slightly_smiling_face:

Of course it’s a hack, but I’m not sure what the correct approach would be. Maybe something like an auth exchange, where the clients ask the server “Who am I?” and then set the local state accordingly. I wouldn’t like local user information to “win” though, so I need to find a way to verify it with every awareness update.

That’s it for now, I’ll update this conversation when I have a solution.

Are you using y-websocket? If so, you could potentially have each client connect to an additional room meant just for that client, and then pass client-specific and server-authoritative info that way.

Hm, I’d like to see if this is possible without a separate WS connection from the client. I see there is a messageAuth type, https://github.com/yjs/y-protocols/blob/master/auth.js, but it’s quite limited.

I wonder if it would be possible to customize the message types and their handlers, then this could be easily done over the same WS.

Sorry for the late answer.

The best approach would probably be to implement your own awareness protocol. It should be pretty easy to polyfill the API.

Another approach would be to intercept awareness information on the server and modify it before you propagate it to other peers. But you need to make sure that the client ignores awareness information that is published using broadcastchannel.

I wonder if it would be possible to customize the message types and their handlers, then this could be easily done over the same WS.

y-protocols is just a template for message handlers. It should be pretty easy to build your own protocol. You don’t have to use y-protocols at all. Simply invent your own message types :wink: