Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silencing "Unable to compute message" #18

Closed
maxkrieger opened this issue Oct 4, 2020 · 4 comments
Closed

Silencing "Unable to compute message" #18

maxkrieger opened this issue Oct 4, 2020 · 4 comments
Assignees
Labels

Comments

@maxkrieger
Copy link

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:

console.error('Unable to compute message')

Could you add a way to silence this error or otherwise allow custom messages to be handled?

@dmonad
Copy link
Member

dmonad commented Oct 5, 2020

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.

@maxkrieger
Copy link
Author

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?

@dmonad
Copy link
Member

dmonad commented Oct 8, 2020

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 })

@maxkrieger
Copy link
Author

Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants