BandwidthHandler | RTCMultiConnection

BandwidthHandler allows you manage application-level bandwidth and many other SDP-attributes.

Usage

var BandwidthHandler = connection.BandwidthHandler;
connection.bandwidth = {
    audio: 128,
    video: 256,
    screen: 300
};
connection.processSdp = function(sdp) {
    sdp = BandwidthHandler.setApplicationSpecificBandwidth(sdp, connection.bandwidth, !!connection.session.screen);
    sdp = BandwidthHandler.setVideoBitrates(sdp, {
        min: connection.bandwidth.video,
        max: connection.bandwidth.video
    });

    sdp = BandwidthHandler.setOpusAttributes(sdp);

    sdp = BandwidthHandler.setOpusAttributes(sdp, {
        'stereo': 1,
        //'sprop-stereo': 1,
        'maxaveragebitrate': connection.bandwidth.audio * 1000 * 8,
        'maxplaybackrate': connection.bandwidth.audio * 1000 * 8,
        //'cbr': 1,
        //'useinbandfec': 1,
        // 'usedtx': 1,
        'maxptime': 3
    });

    return sdp;
};

Description

parameterdescription
BandwidthHandler.setApplicationSpecificBandwidth Set "AS=kbps"
1) first parameter is "sdp" string
2) second parameter is "bandwidth" object {audio: 50, video: 100}
3) last parameter is "isScreen" boolean; which forces 300kbps minimum video bitrates
BandwidthHandler.setVideoBitrates 1) first parameter is "sdp" string
2) last parameter is {min: bitrates, max: bitrates}
BandwidthHandler.setOpusAttributes 1) first parameter is "sdp" string
2) last parameter accepts all following:
{
    'stereo': 1,
    'sprop-stereo': 1,
    'maxaveragebitrate': connection.bandwidth.audio * 1000 * 8,
    'maxplaybackrate': connection.bandwidth.audio * 1000 * 8,
    'cbr': 1,
    'useinbandfec': 1,
    'usedtx': 1,
    'maxptime': 3
}

Demo

<script src="https://rtcmulticonnection.herokuapp.com/dist/RTCMultiConnection.min.js"></script>
<script src="https://rtcmulticonnection.herokuapp.com/socket.io/socket.io.js"></script>

<script>
var connection = new RTCMultiConnection();

// this line is VERY_important
connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

// if you want audio+video conferencing
connection.session = {
    audio: true,
    video: true
};

var BandwidthHandler = connection.BandwidthHandler;
connection.bandwidth = {
    audio: 128,
    video: 256,
    screen: 300
};
connection.processSdp = function(sdp) {
    sdp = BandwidthHandler.setApplicationSpecificBandwidth(sdp, connection.bandwidth, !!connection.session.screen);
    sdp = BandwidthHandler.setVideoBitrates(sdp, {
        min: connection.bandwidth.video,
        max: connection.bandwidth.video
    });

    sdp = BandwidthHandler.setOpusAttributes(sdp);

    sdp = BandwidthHandler.setOpusAttributes(sdp, {
        'stereo': 1,
        //'sprop-stereo': 1,
        'maxaveragebitrate': connection.bandwidth.audio * 1000 * 8,
        'maxplaybackrate': connection.bandwidth.audio * 1000 * 8,
        //'cbr': 1,
        //'useinbandfec': 1,
        // 'usedtx': 1,
        'maxptime': 3
    });

    return sdp;
};

connection.openOrJoin('your-room-id');
</script>