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

Reactive "connected" property #41

Closed
Sjoerd82 opened this issue Feb 7, 2023 · 6 comments
Closed

Reactive "connected" property #41

Sjoerd82 opened this issue Feb 7, 2023 · 6 comments
Assignees

Comments

@Sjoerd82
Copy link

Sjoerd82 commented Feb 7, 2023

Checklist

[X] Are you reporting a bug? Use github issues for bug reports and feature requests. For general questions, please use https://discuss.yjs.dev/
[X] Try to report your issue in the correct repository. Yjs consists of many modules. When in doubt, report it to https://github.com/yjs/yjs/issues/

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

Describe the solution you'd like
On my GUI I'm showing a "connected"/"disconnected" icon. However, the connected property is not reactive.
It would be nice to expose the connected property as an event, or make it otherwise reactive.
I see that an "Observable" class is used, I am not familiar with it. Could it be that SyncedStore already makes this reactive?

Describe alternatives you've considered
I have no (good) alternative ideas.

Additional context
Related:
https://discuss.yjs.dev/t/vue3-syncedstore-reactivity/1683

@Ajayghoshm
Copy link

same here, how to make things reactive?

@dmonad
Copy link
Member

dmonad commented May 4, 2023

The concept of "connected" is not well defined in y-webrtc. In y-websocket, we can say that we are connected to the server. But in y-webrtc, there are many different kinds of endpoints we are connected to.

I assume you are interested in whether you are connected to other peers? Then you could listen to the peers event (it is mentioned in the discussion you mentioned) and update a local variable whenever it is changed.

Observable is a simple class that enabled you to listen to events: instance.on('event', function). Yjs & y-webrtc are not reactive.

@Ajayghoshm
Copy link

True, i tried using the .on(peer,()=>{}) but it gives me inconsistent data, when i rejoin the same room again from the same system, instead of having only actual peer list, I have 3 or 4 peers based on the number of times i joined.

Refer screenshot

Screenshot 2023-05-05 at 8 31 52 AM

@dmonad
Copy link
Member

dmonad commented May 5, 2023

That sounds about right. There is no distinction between a "remote" peer and a peer that is hosted on the same computer. Maybe you want to use y-websocket instead?

@Ajayghoshm
Copy link

Ajayghoshm commented May 5, 2023

I am trying to use both at same time, y-websocket and y-webrtc with a common awareness, will this approach have any issues?

@dmonad
Copy link
Member

dmonad commented May 5, 2023

Sounds like overkill. But sure, that should work. You can mash yjs-providers however you want. But since there is unnecessary computational overhead you should probably only choose one of them. From what I hear, you want a "connected" event - indicating when you received the "latest state". That really only exist when you use y-websocket. There is no way to know when you synced with all y-webrtc peers (you don't know how many there are - because it's p2p).

@dmonad dmonad closed this as completed May 5, 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

3 participants