Enumerate devices even if first getUserMedia fails

The first getUserMedia was not supposed to be considered critical to the whole
video preview flow.

Scenarios where the user has multiple media sources and one of them was already
in use or had some malfunction problem were forcing a global skip at the video
preview modal even if one of them was available to be used.
This commit is contained in:
Pedro Beschorner Marin 2020-10-28 11:18:34 -03:00 committed by prlanzarin
parent f6217308dd
commit c8ace18f85

View File

@ -215,12 +215,12 @@ class VideoPreview extends Component {
// skipped then we get devices with no labels // skipped then we get devices with no labels
if (hasMediaDevices) { if (hasMediaDevices) {
try { try {
let firstAllowedDeviceId;
navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: 'user' } }) navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: 'user' } })
.then((stream) => { .then((stream) => {
if (!this._isMounted) return; if (!this._isMounted) return;
this.deviceStream = stream; this.deviceStream = stream;
// try and get the deviceId for the initial stream // try and get the deviceId for the initial stream
let firstAllowedDeviceId;
if (stream.getVideoTracks) { if (stream.getVideoTracks) {
const videoTracks = stream.getVideoTracks(); const videoTracks = stream.getVideoTracks();
if (videoTracks.length > 0 && videoTracks[0].getSettings) { if (videoTracks.length > 0 && videoTracks[0].getSettings) {
@ -228,7 +228,9 @@ class VideoPreview extends Component {
firstAllowedDeviceId = trackSettings.deviceId; firstAllowedDeviceId = trackSettings.deviceId;
} }
} }
}).catch((error) => {
this.handleDeviceError('initial_device', error, 'getting initial device');
}).finally(() => {
navigator.mediaDevices.enumerateDevices().then((devices) => { navigator.mediaDevices.enumerateDevices().then((devices) => {
const webcams = []; const webcams = [];
let initialDeviceId; let initialDeviceId;
@ -272,13 +274,11 @@ class VideoPreview extends Component {
}); });
} }
}).catch((error) => { }).catch((error) => {
this.handleDeviceError('enumerate_error', error, 'enumerating devices'); this.handleDeviceError('enumerate', error, 'enumerating devices');
}); });
}).catch((error) => {
this.handleDeviceError('initial_device_error', error, 'getting initial device');
}); });
} catch (error) { } catch (error) {
this.handleDeviceError('grabbing_error', error, 'grabbing initial video stream'); this.handleDeviceError('grabbing', error, 'grabbing initial video stream');
} }
} else { } else {
// TODO: Add an error message when media is globablly disabled // TODO: Add an error message when media is globablly disabled
@ -369,7 +369,7 @@ class VideoPreview extends Component {
handleDeviceError(logCode, error, description) { handleDeviceError(logCode, error, description) {
logger.warn({ logger.warn({
logCode: `video_preview_${logCode}`, logCode: `video_preview_${logCode}_error`,
extraInfo: { extraInfo: {
errorName: error.name, errorName: error.name,
errorMessage: error.message, errorMessage: error.message,