MenuMenu

RTCMultiConnection.beforeAddingStream

You can skip any stream or allow RTCMultiConnection to share a stream with remote users

nativePeer.addStream method will be called only if "beforeAddingStream" permits it.

Usage

connection.beforeAddingStream = function(stream, peer) {
    if(stream.id == 'any-streamid') return; // skip
    if(stream.isScreen) return; // skip
    if(stream.inactive) return; // skip

    // var remoteUserId = peer.userid;
    // var remoteUserExtra = connection.peers[remoteUserId].extra;

    return stream; // otherwise allow RTCMultiConnection to share this stream with remote users
};

Description

parameterdescription
stream MediaStream object
peer remoteUserId = peer.userid
remoteUserExtra = peer.extra

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
};

connection.beforeAddingStream = function(stream, peer) {
    if(peer.userid === 'xyz') {
       // do not share any stream with user "XYZ"
       return;
    }

    return stream;
};

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