Use this method to add additional streams in a LIVE session
connection.addStream({ audio: true, video: true, oneway: true });
connection.addStream({ screen: true, oneway: true, streamCallback: function(stream) { console.log('Screen is successfully captured: ' + stream.getVideoTracks().length); } });
parameter | description |
---|---|
audio | share microphone |
video | share camera |
screen | select and share a screen |
oneway | only you will share; all others will merely receive it |
streamCallback |
this callback is fired if stream is successfully captured. use this callback to set stream-stop-listeners so that you can check if screen sharing is stopped etc. |
Always try to set sdpConstraints and mediaConstraints before calling "addStream" method:
connection.sdpConstraints.mandatory = { OfferToReceiveAudio: true, OfferToReceiveVideo: true }; connection.mediaConstraints = { video: true, audio: true }; connection.addStream({ screen: true, oneway: true });
You can enable text-chat or file-sharing in a LIVE video session:
connection.addStream({ data: true });
You can capture a stream yourself and share it using "addStream" method:
navigator.getDisplayMedia({ video: true }).then(externalStream => { connection.addStream(externalStream); }, error => { alert(error); });
<script src="https://rtcmulticonnection.herokuapp.com/dist/RTCMultiConnection.min.js"></script> <script src="https://rtcmulticonnection.herokuapp.com/socket.io/socket.io.js"></script> <hr><button id="share-video">Share Video</button><hr> <script> var connection = new RTCMultiConnection(); // this line is VERY_important connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/'; // if you want audio-only session connection.session = { audio: true }; connection.mediaConstraints = { video: false, audio: true }; connection.sdpConstraints.mandatory = { OfferToReceiveAudio: true, OfferToReceiveVideo: true }; connection.openOrJoin('your-room-id'); document.getElementById('share-video').onclick = function() { this.disabled = true; connection.mediaConstraints.video = true; connection.addStream({ video: true, oneway: true }); }; </script>