Changes after code review

This commit is contained in:
tsareg 2016-05-27 18:49:26 +03:00
parent ccdba03888
commit f574dbe056
3 changed files with 186 additions and 88 deletions

View File

@ -399,12 +399,12 @@ export default {
// If both requests for 'audio' + 'video' and 'audio' only // If both requests for 'audio' + 'video' and 'audio' only
// failed, we assume that there is some problems with user's // failed, we assume that there is some problems with user's
// microphone and show corresponding dialog. // microphone and show corresponding dialog.
APP.UI.showDeviceErrorDialog('microphone', audioOnlyError); APP.UI.showDeviceErrorDialog(audioOnlyError, null);
} else { } else {
// If request for 'audio' + 'video' failed, but request for // If request for 'audio' + 'video' failed, but request for
// 'audio' only was OK, we assume that we had problems with // 'audio' only was OK, we assume that we had problems with
// camera and show corresponding dialog. // camera and show corresponding dialog.
APP.UI.showDeviceErrorDialog('camera', audioAndVideoError); APP.UI.showDeviceErrorDialog(null, audioAndVideoError);
} }
} }
@ -563,56 +563,78 @@ export default {
} }
function createNewTracks(type, cameraDeviceId, micDeviceId) { function createNewTracks(type, cameraDeviceId, micDeviceId) {
let audioOnlyError, videoOnlyError; let audioTrackCreationError;
let videoTrackCreationError;
return createLocalTracks(type, cameraDeviceId, micDeviceId) let audioRequested = type.indexOf('audio') !== -1;
.then(onTracksCreated) let videoRequested = type.indexOf('video') !== -1;
.catch((err) => { let promise;
// if we tried to create both audio and video tracks
// at once and failed, let's try again only with
// audio. Such situation may happen in case if we
// granted access only to microphone, but not to
// camera.
if (type.indexOf('audio') !== -1
&& type.indexOf('video') !== -1) {
return createLocalTracks(['audio'], null,
micDeviceId);
} else if (type.indexOf('audio') !== -1) {
audioOnlyError = err;
} else if (type.indexOf('video') !== -1) {
videoOnlyError = err;
}
if (audioRequested && micDeviceId !== null) {
if (videoRequested && cameraDeviceId !== null) {
promise = createLocalTracks(
type, cameraDeviceId, micDeviceId)
.catch(() => {
return Promise.all([
createAudioTrack(false),
createVideoTrack(false)]);
}) })
.then(onTracksCreated) .then((audioTracks, videoTracks) => {
.catch((err) => { if (audioTrackCreationError) {
// if we tried to create both audio and video tracks if (videoTrackCreationError) {
// at once and failed, let's try again only with APP.UI.showDeviceErrorDialog(
// video. Such situation may happen in case if we audioTrackCreationError,
// granted access only to camera, but not to videoTrackCreationError);
// microphone. } else {
audioOnlyError = err; APP.UI.showDeviceErrorDialog(
if (type.indexOf('audio') !== -1 audioTrackCreationError,
&& type.indexOf('video') !== -1) {
return createLocalTracks(['video'],
cameraDeviceId,
null); null);
} }
}) } else if (videoTrackCreationError) {
.then(onTracksCreated)
.catch((err) => {
videoOnlyError = err;
if (videoOnlyError) {
APP.UI.showDeviceErrorDialog( APP.UI.showDeviceErrorDialog(
'camera', videoOnlyError); null,
videoTrackCreationError);
} }
if (audioOnlyError) { return audioTracks.concat(videoTracks);
APP.UI.showDeviceErrorDialog(
'microphone', audioOnlyError);
}
}); });
} else {
promise = createAudioTrack();
}
} else if (videoRequested && cameraDeviceId !== null) {
promise = createVideoTrack();
} else {
promise = Promise.resolve([]);
}
return promise
.then(onTracksCreated);
function createAudioTrack(showError) {
return createLocalTracks(['audio'], null, micDeviceId)
.catch(err => {
audioTrackCreationError = err;
if (showError) {
APP.UI.showDeviceErrorDialog(err, null);
}
return [];
});
}
function createVideoTrack(showError) {
return createLocalTracks(
['video'], cameraDeviceId, null)
.catch(err => {
videoTrackCreationError = err;
if (showError) {
APP.UI.showDeviceErrorDialog(null, err);
}
return [];
});
}
} }
function onTracksCreated(tracks) { function onTracksCreated(tracks) {
@ -1034,15 +1056,20 @@ export default {
// TrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR // TrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR
// TrackErrors.GENERAL // TrackErrors.GENERAL
// and any other // and any other
let dialogTxt = APP.translation.generateTranslationHTML( let dialogTxt;
err.name === TrackErrors.PERMISSION_DENIED let dialogTitle;
? "dialog.screenSharingPermissionDeniedError"
: "dialog.failtoinstall");
let dialogTitle = APP.translation.generateTranslationHTML( if (err.name === TrackErrors.PERMISSION_DENIED) {
err.name === TrackErrors.PERMISSION_DENIED dialogTxt = APP.translation.generateTranslationHTML(
? "dialog.permissionDenied" "dialog.screenSharingPermissionDeniedError");
: "dialog.error"); dialogTitle = APP.translation.generateTranslationHTML(
"dialog.error");
} else {
dialogTxt = APP.translation.generateTranslationHTML(
"dialog.failtoinstall");
dialogTitle = APP.translation.generateTranslationHTML(
"dialog.permissionDenied");
}
APP.UI.messageHandler.openDialog(dialogTitle, dialogTxt, false); APP.UI.messageHandler.openDialog(dialogTitle, dialogTxt, false);
}); });
@ -1404,7 +1431,7 @@ export default {
APP.settings.setCameraDeviceId(cameraDeviceId); APP.settings.setCameraDeviceId(cameraDeviceId);
}) })
.catch((err) => { .catch((err) => {
APP.UI.showDeviceErrorDialog('camera', err); APP.UI.showDeviceErrorDialog(null, err);
APP.UI.setSelectedCameraFromSettings(); APP.UI.setSelectedCameraFromSettings();
}); });
} }
@ -1420,7 +1447,7 @@ export default {
APP.settings.setMicDeviceId(micDeviceId); APP.settings.setMicDeviceId(micDeviceId);
}) })
.catch((err) => { .catch((err) => {
APP.UI.showDeviceErrorDialog('microphone', err); APP.UI.showDeviceErrorDialog(err, null);
APP.UI.setSelectedMicFromSettings(); APP.UI.setSelectedMicFromSettings();
}); });
} }

View File

@ -226,6 +226,8 @@
"doNotShowWarningAgain": "Don't show this warning again", "doNotShowWarningAgain": "Don't show this warning again",
"permissionDenied": "Permission Denied", "permissionDenied": "Permission Denied",
"screenSharingPermissionDeniedError": "You have not granted permission to share your screen.", "screenSharingPermissionDeniedError": "You have not granted permission to share your screen.",
"micErrorPresent": "There was an error connecting to your microphone.",
"cameraErrorPresent": "There was an error connecting to your camera.",
"cameraUnsupportedResolutionError": "Your camera does not support required video resolution.", "cameraUnsupportedResolutionError": "Your camera does not support required video resolution.",
"cameraUnknownError": "Cannot use camera for a unknown reason.", "cameraUnknownError": "Cannot use camera for a unknown reason.",
"cameraPermissionDeniedError": "You have not granted permission to use your camera.", "cameraPermissionDeniedError": "You have not granted permission to use your camera.",

View File

@ -1155,41 +1155,93 @@ UI.showExtensionRequiredDialog = function (url) {
}; };
/** /**
* Shows dialog with information about camera or microphone error. * Shows dialog with combined information about camera and microphone errors.
* @param {'microphone'|'camera'} type * @param {JitsiTrackError} micError
* @param {JitsiTrackError} error * @param {JitsiTrackError} cameraError
*/ */
UI.showDeviceErrorDialog = function (type, error) { UI.showDeviceErrorDialog = function (micError, cameraError) {
if (type !== "microphone" && type !== "camera") { let localStoragePropName = "doNotShowErrorAgain";
throw new Error("Invalid device type"); let isMicJitsiTrackErrorAndHasName = micError && micError.name &&
micError instanceof JitsiMeetJS.JitsiTrackError;
let isCameraJitsiTrackErrorAndHasName = cameraError && cameraError.name &&
cameraError instanceof JitsiMeetJS.JitsiTrackError;
let showDoNotShowWarning = false;
if (micError && cameraError && isMicJitsiTrackErrorAndHasName &&
isCameraJitsiTrackErrorAndHasName) {
showDoNotShowWarning = true;
} else if (micError && isMicJitsiTrackErrorAndHasName && !cameraError) {
showDoNotShowWarning = true;
} else if (cameraError && isCameraJitsiTrackErrorAndHasName && !micError) {
showDoNotShowWarning = true;
} }
if (error.name && error instanceof JitsiMeetJS.JitsiTrackError && if (micError) {
window.localStorage[type + "DoNotShowErrorAgain-" + error.name] localStoragePropName += "-mic-" + micError.name;
=== "true") { }
if (cameraError) {
localStoragePropName += "-camera-" + cameraError.name;
}
if (showDoNotShowWarning) {
if (window.localStorage[localStoragePropName] === "true") {
return; return;
} }
}
let titleKey = error.name === TrackErrors.PERMISSION_DENIED let title = getTitleKey();
? "dialog.permissionDenied" let titleMsg = `<span data-i18n="${title}"></span>`;
: "dialog.error", let cameraJitsiTrackErrorMsg = cameraError
errorMsg = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP[type][error.name] || ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[cameraError.name]
JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP[type][TrackErrors.GENERAL], : undefined;
title = `<span data-i18n="${titleKey}"></span>`, let micJitsiTrackErrorMsg = micError
message = "<h4 data-i18n='" + errorMsg + "'></h4>" + ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[micError.name]
(!JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP[type][error.name] : undefined;
&& error.message let cameraErrorMsg = cameraError
? "<div>" + error.message + "</div>" ? cameraJitsiTrackErrorMsg ||
: "") + JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.GENERAL]
"<label>" + : "";
"<input type='checkbox' id='doNotShowWarningAgain'> " + let micErrorMsg = micError
(error instanceof JitsiMeetJS.JitsiTrackError && error.name ? micJitsiTrackErrorMsg ||
? "<span data-i18n='dialog.doNotShowWarningAgain'></span>" JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.GENERAL]
: "") + : "";
"</label>"; let additionalCameraErrorMsg = !cameraJitsiTrackErrorMsg && cameraError &&
cameraError.message
? `<div>${cameraError.message}</div>`
: ``;
let additionalMicErrorMsg = !micJitsiTrackErrorMsg && micError &&
micError.message
? `<div>${micError.message}</div>`
: ``;
let doNotShowWarningAgainSection = showDoNotShowWarning
? `<label>
<input type='checkbox' id='doNotShowWarningAgain'>
<span data-i18n='dialog.doNotShowWarningAgain'></span>
</label>`
: ``;
let message = '';
if (micError) {
message = `
${message}
<h3 data-i18n='dialog.micErrorPresent'></h3>
<h4 data-i18n='${micErrorMsg}'></h4>
${additionalMicErrorMsg}`;
}
if (cameraError) {
message = `
${message}
<h3 data-i18n='dialog.cameraErrorPresent'></h3>
<h4 data-i18n='${cameraErrorMsg}'></h4>
${additionalCameraErrorMsg}`;
}
message = `${message}${doNotShowWarningAgainSection}`;
messageHandler.openDialog( messageHandler.openDialog(
title, titleMsg,
message, message,
false, false,
{Ok: true}, {Ok: true},
@ -1200,14 +1252,31 @@ UI.showDeviceErrorDialog = function (type, error) {
let input = form.find("#doNotShowWarningAgain"); let input = form.find("#doNotShowWarningAgain");
if (input.length) { if (input.length) {
window.localStorage[type + "DoNotShowErrorAgain-" window.localStorage[localStoragePropName] =
+ error.name] = input.prop("checked"); input.prop("checked");
} }
} }
} }
); );
APP.translation.translateElement($(".jqibox")); APP.translation.translateElement($(".jqibox"));
function getTitleKey() {
let title = "dialog.error";
if (micError && micError.name === TrackErrors.PERMISSION_DENIED) {
if (cameraError && cameraError.name === TrackErrors.PERMISSION_DENIED) {
title = "dialog.permissionDenied";
} else if (!cameraError) {
title = "dialog.permissionDenied";
}
} else if (cameraError &&
cameraError.name === TrackErrors.PERMISSION_DENIED) {
title = "dialog.permissionDenied";
}
return title;
}
}; };
UI.updateDevicesAvailability = function (id, devices) { UI.updateDevicesAvailability = function (id, devices) {