Giter VIP home page Giter VIP logo

Comments (2)

iwuvjhdva avatar iwuvjhdva commented on June 15, 2024

The bug still persists, please reopen.

If a participant dies unexpectedly (say, a laptop lid has been closed or the browser window killed), the initiator reports "Peer connection seems has been disconnected between you and <...>" in the logs but onleave() event is not actually raised, I did a fix for that by adding this into oniceconnectionstatechange():

  •                        // TODO: update the file after fixing
    
    •                        // https://github.com/muaz-khan/RTCMultiConnection-experimental/issues/2
      
    •                        connection.onleave({
      
    •                            userid: _config.userid,
      
    •                            extra: _config.extra,
      
    •                            entireSessionClosed: connection.isInitiator
      
    •                        });
      

from rtcmulticonnection.

muaz-khan avatar muaz-khan commented on June 15, 2024

iceConnectionState==disconnected happens too often, even if bandwidth is overused by any other application e.g. skype. Though ICE-Agent quickly makes STUN-binding requests and changes it to connected/stable again.

iceConnectionState==disconnected also happens in renegotiation cases.

So, we can't fire connection.leave in case, when iceConnectionState==disconnected.

Check this snippet:

connection.ondisconnected = function (event) {
    log('Peer connection seems has been disconnected between you and', event.userid);

    if (isEmpty(connection.channels)) return;
    if (!connection.channels[event.userid]) return;

    // use WebRTC data channels to detect user's presence
    connection.channels[event.userid].send({
        checkingPresence: true
    });

    // wait 5 seconds, if target peer didn't response, simply disconnect
    setTimeout(function () {
        // iceConnectionState == 'disconnected' occurred out of low-bandwidth
        // or internet connectivity issues
        if (connection.peers[event.userid].connected) {
            delete connection.peers[event.userid].connected;
            return;
        }

        // to make sure this user's all remote streams are removed.
        for (var stream in connection.streams) {
            stream = connection.streams[stream];
            if (stream.userid == event.userid && stream.type == 'remote') {
                connection.onstreamended(stream.streamObject);
            }
        }

        connection.remove(event.userid);
    }, 5000);
};

As you can see, I'm checking presence of the target-peer only if WebRTC data connection was used. Previously I was relying on socket.io i.e. signaling medium however I found many cases where socket.io disconnects or keeps disconnected whilst peer connection should work.

You can easily override above ondisconnected event like this:

connection.onconnected = function (event) {
    event.peer.onCustomMessage = function (message) {
        if (message.areYouThere) {
            event.peer.sendCustomMessage({
                yesIAmThere: true
            });
        }

        if (message.yesIAmThere) {
            connection.peers[event.userid].connected = true;
        }
    };
};


connection.ondisconnected = function (event) {
    event.peer.sendCustomMessage({
        areYouThere: true
    });

    // wait 5 seconds, if target peer didn't response, simply disconnect
    setTimeout(function () {
        // iceConnectionState == 'disconnected' occurred out of low-bandwidth
        // or internet connectivity issues
        if (connection.peers[event.userid].connected) {
            delete connection.peers[event.userid].connected;
            return;
        }

        // to make sure this user's all remote streams are removed.
        for (var stream in connection.streams) {
            stream = connection.streams[stream];
            if (stream.userid == event.userid && stream.type == 'remote') {
                connection.onstreamended(stream.streamObject);
            }
        }

        connection.remove(event.userid);
    }, 5000);
};

from rtcmulticonnection.

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.