Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
Changes after code review
tsaregf574dbe056c2
diff --git a/conference.js b/conference.jsindex 09d33d0115..95de0ae203 100644--- a/conference.js+++ b/conference.js@@ -399,12 +399,12 @@ export default {// If both requests for 'audio' + 'video' and 'audio' only// failed, we assume that there is some problems with user's// microphone and show corresponding dialog.- APP.UI.showDeviceErrorDialog('microphone', audioOnlyError);+ APP.UI.showDeviceErrorDialog(audioOnlyError, null);} else {// If request for 'audio' + 'video' failed, but request for// 'audio' only was OK, we assume that we had problems with// 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) {- let audioOnlyError, videoOnlyError;-- return createLocalTracks(type, cameraDeviceId, micDeviceId)- .then(onTracksCreated)- .catch((err) => {- // 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;- }-- })- .then(onTracksCreated)- .catch((err) => {- // if we tried to create both audio and video tracks- // at once and failed, let's try again only with- // video. Such situation may happen in case if we- // granted access only to camera, but not to- // microphone.- audioOnlyError = err;- if (type.indexOf('audio') !== -1- && type.indexOf('video') !== -1) {- return createLocalTracks(['video'],- cameraDeviceId,- null);- }- })- .then(onTracksCreated)- .catch((err) => {- videoOnlyError = err;-- if (videoOnlyError) {- APP.UI.showDeviceErrorDialog(- 'camera', videoOnlyError);- }-- if (audioOnlyError) {- APP.UI.showDeviceErrorDialog(- 'microphone', audioOnlyError);- }- });+ let audioTrackCreationError;+ let videoTrackCreationError;+ let audioRequested = type.indexOf('audio') !== -1;+ let videoRequested = type.indexOf('video') !== -1;+ let promise;++ if (audioRequested && micDeviceId !== null) {+ if (videoRequested && cameraDeviceId !== null) {+ promise = createLocalTracks(+ type, cameraDeviceId, micDeviceId)+ .catch(() => {+ return Promise.all([+ createAudioTrack(false),+ createVideoTrack(false)]);+ })+ .then((audioTracks, videoTracks) => {+ if (audioTrackCreationError) {+ if (videoTrackCreationError) {+ APP.UI.showDeviceErrorDialog(+ audioTrackCreationError,+ videoTrackCreationError);+ } else {+ APP.UI.showDeviceErrorDialog(+ audioTrackCreationError,+ null);+ }+ } else if (videoTrackCreationError) {+ APP.UI.showDeviceErrorDialog(+ null,+ videoTrackCreationError);+ }++ return audioTracks.concat(videoTracks);+ });+ } 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) {@@ -1034,15 +1056,20 @@ export default {// TrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR// TrackErrors.GENERAL// and any other- let dialogTxt = APP.translation.generateTranslationHTML(- err.name === TrackErrors.PERMISSION_DENIED- ? "dialog.screenSharingPermissionDeniedError"- : "dialog.failtoinstall");-- let dialogTitle = APP.translation.generateTranslationHTML(- err.name === TrackErrors.PERMISSION_DENIED- ? "dialog.permissionDenied"- : "dialog.error");+ let dialogTxt;+ let dialogTitle;++ if (err.name === TrackErrors.PERMISSION_DENIED) {+ dialogTxt = APP.translation.generateTranslationHTML(+ "dialog.screenSharingPermissionDeniedError");+ 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);});@@ -1404,7 +1431,7 @@ export default {APP.settings.setCameraDeviceId(cameraDeviceId);}).catch((err) => {- APP.UI.showDeviceErrorDialog('camera', err);+ APP.UI.showDeviceErrorDialog(null, err);APP.UI.setSelectedCameraFromSettings();});}@@ -1420,7 +1447,7 @@ export default {APP.settings.setMicDeviceId(micDeviceId);}).catch((err) => {- APP.UI.showDeviceErrorDialog('microphone', err);+ APP.UI.showDeviceErrorDialog(err, null);APP.UI.setSelectedMicFromSettings();});}diff --git a/lang/main.json b/lang/main.jsonindex 0007c544fb..2cc4ab304e 100644--- a/lang/main.json+++ b/lang/main.json@@ -226,6 +226,8 @@"doNotShowWarningAgain": "Don't show this warning again","permissionDenied": "Permission Denied","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.","cameraUnknownError": "Cannot use camera for a unknown reason.","cameraPermissionDeniedError": "You have not granted permission to use your camera.",diff --git a/modules/UI/UI.js b/modules/UI/UI.jsindex 40b12180df..8b50f3041c 100644--- a/modules/UI/UI.js+++ b/modules/UI/UI.js@@ -1155,41 +1155,93 @@ UI.showExtensionRequiredDialog = function (url) {};/**- * Shows dialog with information about camera or microphone error.- * @param {'microphone'|'camera'} type- * @param {JitsiTrackError} error- */-UI.showDeviceErrorDialog = function (type, error) {- if (type !== "microphone" && type !== "camera") {- throw new Error("Invalid device type");+ * Shows dialog with combined information about camera and microphone errors.+ * @param {JitsiTrackError} micError+ * @param {JitsiTrackError} cameraError+ */+UI.showDeviceErrorDialog = function (micError, cameraError) {+ let localStoragePropName = "doNotShowErrorAgain";+ 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 &&- window.localStorage[type + "DoNotShowErrorAgain-" + error.name]- === "true") {- return;+ if (micError) {+ localStoragePropName += "-mic-" + micError.name;+ }++ if (cameraError) {+ localStoragePropName += "-camera-" + cameraError.name;+ }++ if (showDoNotShowWarning) {+ if (window.localStorage[localStoragePropName] === "true") {+ return;+ }+ }++ let title = getTitleKey();+ let titleMsg = `<span data-i18n="${title}"></span>`;+ let cameraJitsiTrackErrorMsg = cameraError+ ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[cameraError.name]+ : undefined;+ let micJitsiTrackErrorMsg = micError+ ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[micError.name]+ : undefined;+ let cameraErrorMsg = cameraError+ ? cameraJitsiTrackErrorMsg ||+ JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.GENERAL]+ : "";+ let micErrorMsg = micError+ ? micJitsiTrackErrorMsg ||+ JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.GENERAL]+ : "";+ 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}`;}- let titleKey = error.name === TrackErrors.PERMISSION_DENIED- ? "dialog.permissionDenied"- : "dialog.error",- errorMsg = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP[type][error.name] ||- JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP[type][TrackErrors.GENERAL],- title = `<span data-i18n="${titleKey}"></span>`,- message = "<h4 data-i18n='" + errorMsg + "'></h4>" +- (!JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP[type][error.name]- && error.message- ? "<div>" + error.message + "</div>"- : "") +- "<label>" +- "<input type='checkbox' id='doNotShowWarningAgain'> " +- (error instanceof JitsiMeetJS.JitsiTrackError && error.name- ? "<span data-i18n='dialog.doNotShowWarningAgain'></span>"- : "") +- "</label>";+ if (cameraError) {+ message = `+ ${message}+ <h3 data-i18n='dialog.cameraErrorPresent'></h3>+ <h4 data-i18n='${cameraErrorMsg}'></h4>+ ${additionalCameraErrorMsg}`;+ }++ message = `${message}${doNotShowWarningAgainSection}`;messageHandler.openDialog(- title,+ titleMsg,message,false,{Ok: true},@@ -1200,14 +1252,31 @@ UI.showDeviceErrorDialog = function (type, error) {let input = form.find("#doNotShowWarningAgain");if (input.length) {- window.localStorage[type + "DoNotShowErrorAgain-"- + error.name] = input.prop("checked");+ window.localStorage[localStoragePropName] =+ input.prop("checked");}}});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) {