Redundant messages?

Hey!
I’m trying to understand one thing and hope you can help me.
The question is about awareness protocol and its integration with y-websocket.
We have _awarenessUpdateHandler here https://github.com/yjs/y-websocket/blob/master/src/y-websocket.js#L274 that handles every change to awareness state and broadcasts it. And I understand why we need it when origin='local'. But what if the change comes to us from another client (origin will be the provider itself I guess)? I can see that every message that the client receives is echoed by this code back. But isn’t it redundant?

It’s kind of a problem for me because when you have multiple clients and multiple server nodes connected by pub/sub then only one message from one client raises an avalanche.

The awareness protocol doesn’t use the “origin” concept that is used in Yjs.

Awareness is technically a separate CRDT that is maintained in https://github.com/yjs/y-protocols.

The solution is probably fairly simple. If you receive an awareness message from the pubsub channel, you need to make sure that you don’t send it back. Every time an update is applied to Awareness, it emits a change event. Make sure that when you apply an update from pubsub, you ignore the change event.

Yeah, actually the only thing I do on ‘change’ is sending the update to the clients connected to this node. It’s the thing I can control. But again, what about y-websocket code, what is the reason for this logic? Why do we need to echo every external change?

You don’t need to every message. However, you can if that makes it easier for you… You only need to make sure that every client receives all awareness messages at least once.

If you don’t want to broadcast every message then you need to make sure that your provider doesn’t do that. As I said, you could implement your own check.

Quick correction: use the update event not the change event. This is all documented in docs.yjs.dev and the y-protocols package.

1 Like