Closed maxkrieger closed 3 years ago
Mi Max,
What kind of overhead are you talking about?
Cursor positions should be propagated using the awareness protocol. https://github.com/yjs/y-protocols#awarenessprotocolawareness-class
In most cases, the Awareness instance should work better than implementing your own protocol. y-webrtc doesn't guarantee a totally connected network so you need some CRDT to propagate data. Otherwise, you will likely run into sync issues.
If you are interested we can discuss an extension to the y-webrtc protocol that handles custom messages. Some kind of "custom" message format.
This was exactly what I needed, thanks so much!
Btw, for streams, I only have access to the peerId
because of the way the simple-peer
api works -- but I'd like to match that peerId
with its corresponding ydoc id
immediately so that I know whose stream is whose. I was thinking of attaching the room.peerId
to each peer's awareness state as soon as it becomes available so that I can match up the proper stream just by querying the awareness states for the right peerId
.
However the room
is null until the client connects to the TURN(?) servers, so I can't access my own peerId
until some inaccessible connect
event. Right now I'm just waiting for the first event to come through to check the room
object, but is there a more principled way of getting my peerId
as soon as it's available?
Hi @maxkrieger , you could wait for the key
promise.
Before we can create a room, we need to compute the encryption key which is an asynchronous background call.
The proper way to wait for the room would be provider.key.then(() => { provider.room != null })
Thanks so much!
In my app I'm using the simple-peer method
peer.send(mymessage)
to get around some of the overhead(?) involved in the yjs CRDT: i.e., to broadcast cursor position. However, because of the switch statement in this library, unknown types of messages throw an error:https://github.com/yjs/y-webrtc/blob/d9f2b28b2ab28edfc11a0b0b48f3bc0a5919f8bf/src/y-webrtc.js#L117
Could you add a way to silence this error or otherwise allow custom messages to be handled?