WebRTC Broadcasting using RTCMultiConnection
© 2013 Muaz Khan<@muazkh> » @WebRTC Experiments » Google+ » What's New?
#123456789
- Mesh networking model is implemented to open multiple interconnected peer connections
- Maximum peer connections limit is 256 (on chrome)
Feedback
It is one-way broadcasting; media stream is attached only by the broadcaster.
It means that, if 10 people are watching your one-way broadcasted audio/video stream; on your system:
- 10 RTP ports are opened to send video upward i.e. outgoing video
- 10 RTP ports are opened to send audio upward i.e. outgoing audio
And on participants system:
- 10 RTP ports are opened to receive video i.e. incoming video
- 10 RTP ports are opened to receive audio i.e. incoming audio
Maximum bandwidth used by each video RTP port (media-track) is about 1MB. You're streaming audio and video tracks. You must be careful when streaming video over more than one peers. If you're broadcasting audio/video over 10 peers; it means that 20MB bandwidth is required on your system to stream-up (broadcast/transmit) your video. Otherwise; you'll face connection lost; CPU usage issues; and obviously audio-lost/noise/echo issues.
You can handle such things using "b=AS" (application specific bandwidth) session description parameter values to deliver a little bit low quality video.
// removing existing bandwidth lines sdp = sdp.replace( /b=AS([^\r\n]+\r\n)/g , ''); // setting "outgoing" audio RTP port's bandwidth to "50kbit/s" sdp = sdp.replace( /a=mid:audio\r\n/g , 'a=mid:audio\r\nb=AS:50\r\n'); // setting "outgoing" video RTP port's bandwidth to "256kbit/s" sdp = sdp.replace( /a=mid:video\r\n/g , 'a=mid:video\r\nb=AS:256\r\n');
Possible issues:
- Blurry video experience
- Unclear voice and audio lost
- Bandwidth issues / slow streaming / CPU overwhelming
Solution? Obviously a media server!
How to broadcast video?
- session.audio=true
- session.video=true
- session.oneway=true
// https://www.webrtc-experiment.com/RTCMultiConnection-v1.4.js var connection = new RTCMultiConnection(); // setup session; along with "direction" to "oneway" connection.session = { audio: true, video: true, oneway: true }; // on local/remote media stream connection.onstream = function(e) {} // setup signaling to search for existing sessions connection.connect(); // setup new session document.getElementById('initiator').onclick = function() { connection.open(); };