Using the API navigator.mediaDevices.enumerateDevices() I got the ID of the devices available in the computer, but I don't know how to tell the navigator that I want to switch the camera or mic. In the forums there are many examples, but none is clear since webRTC changed many times the API and its reference. There is only one example in the web, proposed by webRTC but I can't really understand it or at least I cannot find in its code what I need.
I have not tried much because I am very new with webRTC...
if(!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) console.log('Enumerate Media Devices from getUserMedia is not supported');
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
devices.forEach(function(device) {
if (device.kind == 'audioinput' || device.kind == 'audiooutput') $scope.devicesAudio.push(device);
else if (device.kind == 'videoinput' || device.kind == 'videooutput') $scope.devicesVideo.push(device);
else $scope.devices.push(device);
});
})
.catch(function(err) {
console.log(err.name + ':' + err.message);
});
$scope.selectDevice = function(device) {
if(device.kind == 'videooutput' || device.kind == 'videoinput') {
console.log('video Device selected' + ' DEVICE_ID: ' + device.deviceId);
}
else if(device.kind == 'audioinput' || device.kind == 'videooutput') {
console.log('Audio device selected' + ' DEVICE_ID: ' + device.deviceId);
};
};
I hope that my application has the option to change the camera and the microphone...