简体   繁体   中英

webRTC: How to detect audio/video presence in Stream?

I would like to know the tracks presence in received stream onaddstream callback. Video calling is working well but I would like to make. audio only call, so I just passed audio:true,video:false in getUserMedia constraints, now when I receive stream I cant figure out tracks presence in stream.

How to know tracks presence in stream?

To Know presence of Audio and Video use getAudioTracks and getVideoTracks .

function checkStream(stream){

   var hasMedia={hasVideo:false,hasAudio:false};

   if(stream.getAudioTracks().length)// checking audio presence
      hasMedia.hasAudio=true;

   if(stream.getVideoTracks().length)// checking video presence
      hasMedia.hasVideo=true;

    return hasMedia; 
}

To stop passing Video in stream change offer and answer constrinats.

constraints = {
            optional: [],
            mandatory: {
                OfferToReceiveAudio: true,
                OfferToReceiveVideo: false
            }
        };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM