muaz-khan / WebRTC-Scalable-Broadcast

This module simply initializes socket.io and configures it in a way that single broadcast can be relayed over unlimited users without any bandwidth/CPU usage issues. Everything happens peer-to-peer!
https://rtcmulticonnection.herokuapp.com/demos/Scalable-Broadcast.html
532 stars 142 forks source link

What happen if one of the peers in the chain has a slow speed connection #9

Open ChStark opened 8 years ago

ChStark commented 8 years ago

Hi, I want to know what happen if on of the peers in the chain has a slow connection , it will slowdown all the new peers isnt it?

Is there any plan to implement something like webtorrent ?

Thanks in advance

alexcroox commented 8 years ago

I am curious about this too. If I have 1000 viewers, would they all be experiencing the optimal latency or would some be experiencing 5 seconds of latency because of 1 client's low bandwidth? How does the server guarantee everyone is viewing real time?

muaz-khan commented 8 years ago

@alexcroox We are currently assuming maximum 20 viewers. Media-Server is the only alternative otherwise.

Regarding @ChStark 's point, usually each peer requires following:

100 MB System Memory (RAM)
150 kbps bandwidth (for normal SD stream)
256 kbps bandwidth (for HD stream)

If a peer merely having 100kbps or lower bandwidth, then VP9 will play its role. It will reduce frame's quality and adjust bandwidth accordingly.

If peer's bandwidth reduces to 20kbps or lower then WebRTC IceAgent may fail making STUN-binding requests; and ice-connection-state may quickly change into disconnected|closed. Socket.io may keep working, though.

If Ice-Connection-State switches into disconnect then RTCMultiConnection-v3 should auto remove (close) current peer. We may need to manually call connection.closeSocket to leave socket.io as well.

We simply need to remove that peer from the chain. We can do this inside onPeerStateChanged event-handler.

connection.onPeerStateChanged = function(state) {
    // or maybe: state.iceConnectionState === 'closed'
    if(state.iceConnectionState.search(/disconnected|closed|failed/gi) !== -1) {
         if(!connection.getAllParticipants().lenght) {
            // if bandwidth <= 20kbps (compare)
            // if peer doesn't have any receiver/viewer
            connection.closeSocket();
         }
    }
};
alexcroox commented 8 years ago

Would something like https://github.com/meetecho/janus-gateway work for ~ 1k viewers (VP8 over WebRTC)?

muaz-khan commented 8 years ago

I think kurento,janus-gateway,etc. works smoothly to broadcast over 50+ users; however I didn't try any of these yet. So donno if they can be scaled to 1000+ or not.