Giter VIP home page Giter VIP logo

Comments (8)

dmonad avatar dmonad commented on August 16, 2024

When a client disconnects, it automatically tries to reconnnect. Are you sure that the client is disconnected when added:webrtc:[98ee6477-5037-49ee-bd20-b8f69928dade] is fired?

from y-webrtc.

disarticulate avatar disarticulate commented on August 16, 2024

Yes.

When I review y-webrtc for the close, (this.peer.on('close', () =>...) the last line is announceSignalingInfo(room) which triggerS:

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

there's the debugs you're seeing. 'true' is conn.connected. So on close, it's announcing signically messages, even though it's closing.

My naive understanding suggests it shouldn't be announcing or, this shouldn't say 'added' from the message :

            const emitPeerChange = webrtcConns.has(data.from) ? () => {} : () =>
              room.provider.emit('peers', [{
                removed: [],
                added: [data.from],
                webrtcPeers: Array.from(room.webrtcConns.keys()),
                bcPeers: Array.from(room.bcConns)
              }])

from y-webrtc.

dmonad avatar dmonad commented on August 16, 2024

There are three types of connections. 1. There are WebRTC connections. The line you mentioned this.peer.on('close', () =>...) is referring to a webrtc conenction. 2. There are BroadcastChannel connections (connections to other peers in the same browser are not handled via WebRTC). 3. There are Websocket connections to a signaling server. announceSignalingInfo sends a message to the websocket/signaling server. When a WebRTC connection closes unexpectedly, we announce ourselves over the signaling server again to reconnect to the closed connection. After a time, the remote client reconnects (either using 1. WebRTC or via 2. BroadcastChannel) and the peers: {added: [..]} event is fired.

from y-webrtc.

disarticulate avatar disarticulate commented on August 16, 2024

alright, what I'm seeing:

    this.peer.on('close', () => {
      this.connected = false
      this.closed = true
      if (room.webrtcConns.has(this.remotePeerId)) {
        room.webrtcConns.delete(this.remotePeerId)
        room.provider.emit('peers', [{
          removed: [this.remotePeerId],
          added: [],
          webrtcPeers: Array.from(room.webrtcConns.keys()),
          bcPeers: Array.from(room.bcConns)
        }])
      }
      checkIsSynced(room)
      this.peer.destroy() ***// should this just be 'this.destroy'***
      log('closed connection to ', logging.BOLD, remotePeerId)
      announceSignalingInfo(room)
    })

the announceSignalingInfo call triggers the announcement and the second client gets a 'peers' notification as the peer being added.

It's possible it's a race condition since I'm just doing it locally between two browsers or it's something stranger with the devserver updating.

from y-webrtc.

dmonad avatar dmonad commented on August 16, 2024

How do you close the connection to the remote client?

from y-webrtc.

disarticulate avatar disarticulate commented on August 16, 2024

refresh the browser -> close is triggered

If it was re-logging in, we'd have a different peerId, but the same peer ID shows up on the second client. That's the log that's shown on the second browser window, which I retested just so:

removed:webrtc:[11064215-ac2b-48e2-bfd8-52966676e517] WebrtcProvider {…}

y-webrtc.js?9b73:270 announceSignalingInfo Room {…} true
...
y-webrtc.js?9b73:270 announceSignalingInfo Room {…} true
...
y-webrtc.js?9b73:270 announceSignalingInfo Room {…} true
eval @ y-webrtc.js?9b73:270
announceSignalingInfo @ y-webrtc.js?9b73:265
eval @ y-webrtc.js?9b73:221
r.emit @ simplepeer.min.js?07cd:6
eval @ simplepeer.min.js?07cd:6
error (async)
_setupData @ simplepeer.min.js?07cd:6
p @ simplepeer.min.js?07cd:6
WebrtcConn @ y-webrtc.js?9b73:183
eval @ y-webrtc.js?9b73:501
setIfUndefined @ map.js?4b35:49
execMessage @ y-webrtc.js?9b73:501
Promise.then (async)
eval @ y-webrtc.js?9b73:515
eval @ observable.js?9732:73
emit @ observable.js?9732:73
websocket.onmessage @ websocket.js?49e4:45
y-webrtc.js?9b73:491 {type: "announce", from: "11064215-ac2b-48e2-bfd8-52966676e517"} "11064215-ac2b-48e2-bfd8-52966676e517"
emitPeerChange @ y-webrtc.js?9b73:491
execMessage @ y-webrtc.js?9b73:502
Promise.then (async)
eval @ y-webrtc.js?9b73:515
eval @ observable.js?9732:73
emit @ observable.js?9732:73
websocket.onmessage @ websocket.js?49e4:45
SyncPeers.js?a801:235

added:webrtc:[11064215-ac2b-48e2-bfd8-52966676e517]

WebrtcConn {room: Room, remotePeerId: "11064215-ac2b-48e2-bfd8-52966676e517", closed: false, connected: false, synced: false, …} WebrtcProvider {…}

from y-webrtc.

dmonad avatar dmonad commented on August 16, 2024

It's possible it's a race condition since I'm just doing it locally between two browsers or it's something stranger with the devserver updating.

This is probably the reason. A devserver often duplicates created objects. Sorry, it is impossible for me to debug this issue. Unless you provide a step-by-step example for how I can reproduce this (without some react dev-server setup) I can't help you.

Can you maybe create a simple project (maybe fork https://github.com/yjs/yjs-demos) and describe the steps to reproduce this issue?

from y-webrtc.

disarticulate avatar disarticulate commented on August 16, 2024

it appears to be chrome specific. I upgraded the demo here:

https://github.com/disarticulate/y-webrtc/tree/master/demo

Reproduce:

  1. open 2 chrome threads (not in same window):
/usr/bin/chromium-browser --user-data-dir=$root/chrome1 --password-store=basic http://localhost:8080/demo/ &
/usr/bin/chromium-browser --user-data-dir=$root/chrome2 --password-store=basic http://localhost:8080/demo/ &
  1. open a firefox browser (just to double check)

  2. wait till added:webrtc:[peerId]

  3. close chrome or refresh chrome

  4. observe console:

removed:webrtc:[fb8ba1ec-759c-4b57-a6d5-fb5f9a19b780] index.js:13:12
synced! 
Object { synced: false }
index.js:25:10
Object { _readableState: {…}, readable: true, _events: {…}, _eventsCount: 2, _maxListeners: undefined, _writableState: {…}, writable: true, allowHalfOpen: false, _id: "f240014", channelName: "7a260e731074938719ec8719f2e19adf96eb1458", … }
SimplePeerExtended.js:44:12
added:webrtc:[fb8ba1ec-759c-4b57-a6d5-fb5f9a19b780]

You may want to use the standard SimplePeer if you think I did something untoward to it.

I'll comment on the rest of that code in the other issue I've got open #20

from y-webrtc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.