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

Emit events when the connected state changes #64

Closed
xaviergonz opened this issue Dec 24, 2023 · 6 comments
Closed

Emit events when the connected state changes #64

xaviergonz opened this issue Dec 24, 2023 · 6 comments
Assignees

Comments

@xaviergonz
Copy link

xaviergonz commented Dec 24, 2023

Is your feature request related to a problem? Please describe.

I'd like a 'connect' and 'close' events to be emitted after y-webrtc has connected/disconnected so that I can show a connection status badge without the need to poll every so often the 'connected' variable in the provider

@dmonad
Copy link
Member

dmonad commented Dec 28, 2023

Hi @xaviergonz ,

Can you please specify? So, do you want an event every time a user is connected to another user, or do you want a connected event when you are connected to the signaling server?

Could you please name a good use-case for the connected event?

The connected event is a farce. You never know when you are connected to all peers. So when exactly should the connected event be emitted?

@xaviergonz
Copy link
Author

Sure. I mean an event that gets emitted when connected is changed. The he use case is for example a react component that renders the connection state and that calls setState when this event is emitted rather than needing to poll connected within a setInterval

@xaviergonz
Copy link
Author

I just read the farce part, what does connected represent then?

@dmonad
Copy link
Member

dmonad commented Dec 28, 2023

Makes sense. I will make a change so that a connected event is emitted.

Sweet project, by the way! I'd love to receive a PR that adds mobx-keystone-yjs to https://github.com/yjs/yjs/#bindings

A bit of background information:

provider.connected was only added so it has a similar API to y-websocket.

It is true once the provider starts looking for other peers. Other peers can be found via signaling servers or via broadcastchannel (cross browser-tab communication). You never know when you are connected to all peers. You also don't know if there are other peers. connected doesn't mean that you are connected to any physical peers working on the same resource as you. It does not change unless you call provider.disconnect()

In contrast to y-websocket, you can never know when you are connected to all sources that collaborate on the same room, as there is (by design) no central registry.

@xaviergonz
Copy link
Author

Thanks for the info! (and the kudos!) I thought connected would give something more useful like if there's an active connection to the signaling server or similar rather than an intent to stay connected, so feel free to ignore the request then.

About the PR, there's one already 😉 yjs/yjs#605

@dmonad
Copy link
Member

dmonad commented Dec 28, 2023

Feel free to use y-websocket & wss://demos.yjs.dev/ws for demos. I recently added more resources, so it should work much better than before.

@dmonad dmonad closed this as completed Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants