Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 296
kongaraju Avatar asked May 27 '13 09:05

kongaraju


1 Answers

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
            }
        };
like image 65
kongaraju Avatar answered Nov 08 '22 17:11

kongaraju