Check if your users has microphone, camera or speakers
Check if your users has microphone, camera or speakers. Check if they are using WebRTC compatible web browser.
You can try DetectRTC live-demo here.
if (connection.DetectRTC.hasMicrophone === false) { alert('Please attach a microphone device.'); // or ignore microphone connection.mediaConstraints.audio = false; connection.session.audio = false; }
if (connection.DetectRTC.hasWebcam === false) { alert('Please attach a camera device.'); // or ignore camera connection.mediaConstraints.video = false; connection.session.video = false; }
if (connection.DetectRTC.hasSpeakers === false) { alert('Please attach a speaker device. You will unable to hear the incoming audios.'); }
// it is recommended to checked above three features inside "DetectRTC.load" method connection.DetectRTC.load(function() { if (connection.DetectRTC.hasMicrophone === true) { // enable microphone connection.mediaConstraints.audio = true; connection.session.audio = true; } if (connection.DetectRTC.hasWebcam === true) { // enable camera connection.mediaConstraints.video = true; connection.session.video = true; } if (connection.DetectRTC.hasSpeakers === false) { // checking for "false" alert('Please attach a speaker device. You will unable to hear the incoming audios.'); } });
connection.DetectRTC.load(function() { // you can access all microphones using "DetectRTC.audioInputDevices" connection.DetectRTC.audioInputDevices.forEach(function(device) { var option = document.createElement('option'); // this is what people see option.innerHTML = device.label; // but this is what inernally used to select relevant device option.value = device.id; // append to your choice document.querySelector('select').appendChild(option); }); // you can access all cameras using "DetectRTC.videoInputDevices" connection.DetectRTC.videoInputDevices.forEach(function(device) { var option = document.createElement('option'); // this is what people see option.innerHTML = device.label; // but this is what inernally used to select relevant device option.value = device.id; // append to your choice document.querySelector('select').appendChild(option); }); });
connection.mediaConstraints = { audio: { mandatory: {}, optional: [{ sourceId: 'your-microphone-id' }] }, video: { mandatory: {}, optional: [{ sourceId: 'your-camera-id' }] } }; if (connection.DetectRTC.browser.name === 'Firefox') { connection.mediaConstraints = { audio: { deviceId: 'your-microphone-id' }, video: { deviceId: 'your-camera-id' } }; }
if (connection.DetectRTC.isWebRTCSupported === false) { alert('Please try a WebRTC compatible web browser e.g. Chrome, Firefox or Opera.'); }
Please check DetectRTC complete documentation here: https://github.com/muaz-khan/DetectRTC
<script src="https://rtcmulticonnection.herokuapp.com/dist/RTCMultiConnection.min.js"></script> <script src="https://rtcmulticonnection.herokuapp.com/socket.io/socket.io.js"></script> <script> var connection = new RTCMultiConnection(); // this line is VERY_important connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/'; connection.session = { audio: false, video: false, data: true // at least data-connection must open if he do not have camera+mic }; connection.DetectRTC.load(function() { if (connection.DetectRTC.hasMicrophone === true) { // enable microphone connection.mediaConstraints.audio = true; connection.session.audio = true; } if (connection.DetectRTC.hasWebcam === true) { // enable camera connection.mediaConstraints.video = true; connection.session.video = true; } if (connection.DetectRTC.hasMicrophone === false && connection.DetectRTC.hasWebcam === false) { // he do not have microphone or camera // so, ignore capturing his devices connection.dontCaptureUserMedia = true; } if (connection.DetectRTC.hasSpeakers === false) { // checking for "false" alert('Please attach a speaker device. You will unable to hear the incoming audios.'); } connection.openOrJoin('your-room-id'); }); </script>