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?

5

1 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like