Advertisement
krot

webrtc checking audioinput videoinput

Jun 19th, 2018
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let checking=["audioinput","videoinput"];
  2. let onlyHas={device:[]};
  3. navigator.mediaDevices.enumerateDevices()
  4. .then((devices)=> {
  5.   let haveAllDevices=true;
  6.   devices.forEach((device)=>{
  7.       console.log(device.kind);
  8.       if( device.kind=="audioinput" ){
  9.         onlyHas.audioinput=true;
  10.         }
  11.          if( device.kind=="videoinput" ){
  12.         onlyHas.videoinput=true;
  13.         }
  14.         onlyHas.device.push(device);
  15.     if(!(device.kind==checking[0] || device.kind==checking[1])){
  16.     haveAllDevices=false;
  17.     }
  18.    });
  19.    //do something about ...
  20. })
  21. .catch(function(err) {
  22.   console.log(err.name + ": " + err.message);
  23. });
  24. if(onlyHas.videoinput===false){
  25.     alert('no cam!');
  26. }
  27. if(onlyHas.audioinput===false){
  28.     alert('no microphone!');
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement