Giter VIP home page Giter VIP logo

Comments (5)

jeffrafter avatar jeffrafter commented on July 17, 2024 5

I was having a similar issue. I replaced the y-webrtc implementation with a stub based on @disarticulate's fork (see also #23) and was able to debug more easily.

One of the things I was seeing was:

Failed to execute 'send' on 'RTCDataChannel': RTCDataChannel.readyState is not 'open'

This was happening fairly consistently when a Safari based client would attempt to join a room with Chrome-based clients.

I looked around for connected issues:

And these helped. Though I haven't fully solved it, I'll keep some notes here: something about the order/state between the two browsers is inconsistent. Chrome <-> Chrome is working well Safari <-> Safari is working well. I tried setting filterBcConns: false when creating the provider to see if it was a broadcast channel problem (this did not help). I removed all crypto (this did not help). I updated simple-peer and Int64 deps (from @disarticulate's version, this did not help).

I'll note that I am dealing with very small documents - chunking was not the problem.

I tried adding two additional checks for this.connected:

    this.peer.on("error", (err) => {
      log("Error in connection to ", logging.BOLD, remotePeerId, ": ", err)
      // THIS LINE IS IMPORTANT WHEN RECONNECTING
      if (!this.connected) return
      announceSignalingInfo(room)
    })

And

    this.peer.on("data", async (data) => {
      const valid = await validMessage(room, data.slice())
      if (!valid)
        return console.warn("!InvalidData", {
          peer: this.peer,
          context: this,
          room,
          data,
        })
      const answer = readPeerMessage(this, data)
      //JEFF: THIS LINE IS IMPORTANT WHEN SETTING UP CONNECTIONS
      if (!this.connected) return
      if (answer !== null) {
        sendWebrtcConn(this, answer)
      }
      return
    })

Which in y-webrtc is here: https://github.com/yjs/y-webrtc/blob/master/src/y-webrtc.js#L228-L237

This fixed almost everything. I also have a heavily offline app that refetches on focus and this really made it feel solid.

The only thing this isn't solving for me is when the browser is offline (not connected to a network provider, navigator.onLine is false... faking it in the Network panel is not enough). In that case the browsers go back to not being able to talk to each other. I see more invalid message errors so an additional check might be needed.

Some conclusions: sending a message when not connected properly crashes the Peer. It goes away entirely and you have to refresh to fix it. But you have to do this to all of the peers and build it up again. If you have an application that refreshes on focus (especially with HMR) this gets very difficult to debug.

I'm interested to know if the this.connected checks feel right. If so I'm happy to open a PR.

from y-webrtc.

dmonad avatar dmonad commented on July 17, 2024

A good first start would be to reproduce the issue and check the logs. This issue might also get fixed by simply updating simple-peer.

from y-webrtc.

froger avatar froger commented on July 17, 2024

Just going through this issue, it seems Safari might have issues with their Webrtc implementations.
(feross/simple-peer#672 (comment), https://bugs.webkit.org/show_bug.cgi?id=198545).

Will try a bunch of safari version as soon as possible.

from y-webrtc.

snqb avatar snqb commented on July 17, 2024

hey, have there been any news on this?
I noticed this behavior while syncing my app data from my laptop(Windows with Brave) to my phone(iOS with Safari)
it does sync fine when you just boot it up, but after some time the connection is lost
and the only remedy is to restart the app

from y-webrtc.

tim-hilt avatar tim-hilt commented on July 17, 2024

Hey, are you sure this issue is limited to Chrome and Safari? I couldn' t get cross browser syncing to work at all. I tested with Safari, Arc and Chrome.

This issue might be related to #63 and #53

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.