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

Duplicate 'close' listeners for WebRTC connection #21

Closed
holtwick opened this issue Jan 5, 2021 · 5 comments
Closed

Duplicate 'close' listeners for WebRTC connection #21

holtwick opened this issue Jan 5, 2021 · 5 comments
Assignees
Labels

Comments

@holtwick
Copy link

holtwick commented Jan 5, 2021

These lines seem to be wrong:
https://github.com/yjs/y-webrtc/blob/master/src/y-webrtc.js#L222-L225

The result of it is, that peers are not removed correctly anymore.

@dmonad
Copy link
Member

dmonad commented Jan 6, 2021

Right. I duplicated that because the close handler is not called when the error event is called. I should have combined that with the previous handler. Although I don't see how this can lead to issues?

@holtwick
Copy link
Author

holtwick commented Jan 6, 2021

After I removed the part completely my issues were gone. The problem was that peers message was emitted, first to with payload telling to remove the peer and then afterwards another one that tried to add it again.

Maybe somewhere here?

y-webrtc/src/y-webrtc.js

Lines 267 to 277 in e0d5d11

const announceSignalingInfo = room => {
signalingConns.forEach(conn => {
// only subcribe if connection is established, otherwise the conn automatically subscribes to all rooms
if (conn.connected) {
conn.send({ type: 'subscribe', topics: [room.name] })
if (room.webrtcConns.size < room.provider.maxConns) {
publishSignalingMessage(conn, room, { type: 'announce', from: room.peerId })
}
}
})
}

dmonad added a commit that referenced this issue Jan 7, 2021
@dmonad
Copy link
Member

dmonad commented Jan 7, 2021

Maybe this is a misunderstanding. The intention is that y-webrtc automatically handles (and reconnects) connections unless you explicitly disconnect the provider instance (then no connection should be possible anymore).

So when the connection to a peer is closed, then it will automatically subscribe to find more peers again.

@holtwick
Copy link
Author

holtwick commented Jan 7, 2021

Whatever the reason was, your change fixed the issue. I had two browser windows being connected via y-webrtc and when reloading one of them the other one showed 2 connections. This is fixed now, probably due to the duplicate listening to 'close' being removed. Thanks!

@dmonad
Copy link
Member

dmonad commented Jan 8, 2021

Oh nice! It makes sense as I simply assumed the second handler would be called after the first one (which might not be the case). Then I will publish a new release of this package as it seems to fix an issue.

@dmonad dmonad closed this as completed Jan 8, 2021
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