How to check web-camera and microphone existence?

1,673 views
Skip to first unread message

tagaism

unread,
Jan 11, 2016, 3:10:19 AM1/11/16
to discuss-webrtc
Hello every one.
I created a WebRTC application where users can have privet video chat.
But, if one of the user doesn't have a web-camera, then getUserMedia doesn't allow him to get connection.
I want make a user, who haven't a cam could make at least a voice chat. 
So, I suppose that I need to make checking of camera existence before getUserMedia occur.
Please, can anyone guide me? Any help will extremely appreciated.  

Christoffer Jansson

unread,
Jan 11, 2016, 3:14:02 AM1/11/16
to discuss-webrtc
Hi,

You could do enumerateDevices and check if there are any devices of kind "videoinput" and then do getUserMedia with the appropriate device types.


/Chris



--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/8282b590-5978-49e8-84ed-79c3c66371e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tagaism

unread,
Mar 5, 2016, 12:53:59 AM3/5/16
to discuss-webrtc
Thanks @Chrisoffer Jannson.
Your answer guided me to the solution.
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
if (navigator.getUserMedia) {
navigator.getUserMedia({video: true, audio: true}, function(){
// Success
// check if mic is provided
navigator.mediaDevices.enumerateDevices().then(function(devices) {
devices.forEach(function(device) {
//if mic is plugged in
if (((device.kind === 'audioinput') && (device.kind === 'videoinput')) || device.kind === 'audioinput') {
//check if mic has permission
//works only in Chrome
if ((device.label).length > 0) {
//go to chat room
};
};
});
}).catch(function(err) {
console.log(err.name + ": " + error.message);
});
},
function(){
// Failure
});
};


Christoffer Jansson

unread,
Mar 5, 2016, 9:07:16 AM3/5/16
to discuss-webrtc
Glad I was able to help ;)

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
/Chris
Reply all
Reply to author
Forward
0 new messages