Sfoglia il codice sorgente

Changes after code review

efficient_tiling
tsareg 9 anni fa
parent
commit
f574dbe056
3 ha cambiato i file con 192 aggiunte e 94 eliminazioni
  1. 90
    63
      conference.js
  2. 2
    0
      lang/main.json
  3. 100
    31
      modules/UI/UI.js

+ 90
- 63
conference.js Vedi File

@@ -399,12 +399,12 @@ export default {
399 399
                     // If both requests for 'audio' + 'video' and 'audio' only
400 400
                     // failed, we assume that there is some problems with user's
401 401
                     // microphone and show corresponding dialog.
402
-                    APP.UI.showDeviceErrorDialog('microphone', audioOnlyError);
402
+                    APP.UI.showDeviceErrorDialog(audioOnlyError, null);
403 403
                 } else {
404 404
                     // If request for 'audio' + 'video' failed, but request for
405 405
                     // 'audio' only was OK, we assume that we had problems with
406 406
                     // camera and show corresponding dialog.
407
-                    APP.UI.showDeviceErrorDialog('camera', audioAndVideoError);
407
+                    APP.UI.showDeviceErrorDialog(null, audioAndVideoError);
408 408
                 }
409 409
             }
410 410
 
@@ -563,56 +563,78 @@ export default {
563 563
                 }
564 564
 
565 565
                 function createNewTracks(type, cameraDeviceId, micDeviceId) {
566
-                    let audioOnlyError, videoOnlyError;
567
-
568
-                    return createLocalTracks(type, cameraDeviceId, micDeviceId)
569
-                        .then(onTracksCreated)
570
-                        .catch((err) => {
571
-                            // if we tried to create both audio and video tracks
572
-                            // at once and failed, let's try again only with
573
-                            // audio. Such situation may happen in case if we
574
-                            // granted access only to microphone, but not to
575
-                            // camera.
576
-                            if (type.indexOf('audio') !== -1
577
-                                && type.indexOf('video') !== -1) {
578
-                                return createLocalTracks(['audio'], null,
579
-                                    micDeviceId);
580
-                            } else if (type.indexOf('audio') !== -1) {
581
-                                audioOnlyError = err;
582
-                            } else if (type.indexOf('video') !== -1) {
583
-                                videoOnlyError = err;
584
-                            }
585
-
586
-                        })
587
-                        .then(onTracksCreated)
588
-                        .catch((err) => {
589
-                            // if we tried to create both audio and video tracks
590
-                            // at once and failed, let's try again only with
591
-                            // video. Such situation may happen in case if we
592
-                            // granted access only to camera, but not to
593
-                            // microphone.
594
-                            audioOnlyError = err;
595
-                            if (type.indexOf('audio') !== -1
596
-                                && type.indexOf('video') !== -1) {
597
-                                return createLocalTracks(['video'],
598
-                                    cameraDeviceId,
599
-                                    null);
600
-                            }
601
-                        })
602
-                        .then(onTracksCreated)
603
-                        .catch((err) => {
604
-                            videoOnlyError = err;
605
-
606
-                            if (videoOnlyError) {
607
-                                APP.UI.showDeviceErrorDialog(
608
-                                    'camera', videoOnlyError);
609
-                            }
610
-
611
-                            if (audioOnlyError) {
612
-                                APP.UI.showDeviceErrorDialog(
613
-                                    'microphone', audioOnlyError);
614
-                            }
615
-                        });
566
+                    let audioTrackCreationError;
567
+                    let videoTrackCreationError;
568
+                    let audioRequested = type.indexOf('audio') !== -1;
569
+                    let videoRequested = type.indexOf('video') !== -1;
570
+                    let promise;
571
+
572
+                    if (audioRequested && micDeviceId !== null) {
573
+                        if (videoRequested && cameraDeviceId !== null) {
574
+                            promise = createLocalTracks(
575
+                                type, cameraDeviceId, micDeviceId)
576
+                                .catch(() => {
577
+                                    return Promise.all([
578
+                                        createAudioTrack(false),
579
+                                        createVideoTrack(false)]);
580
+                                })
581
+                                .then((audioTracks, videoTracks) => {
582
+                                    if (audioTrackCreationError) {
583
+                                        if (videoTrackCreationError) {
584
+                                            APP.UI.showDeviceErrorDialog(
585
+                                                audioTrackCreationError,
586
+                                                videoTrackCreationError);
587
+                                        } else {
588
+                                            APP.UI.showDeviceErrorDialog(
589
+                                                audioTrackCreationError,
590
+                                                null);
591
+                                        }
592
+                                    } else if (videoTrackCreationError) {
593
+                                        APP.UI.showDeviceErrorDialog(
594
+                                            null,
595
+                                            videoTrackCreationError);
596
+                                    }
597
+
598
+                                    return audioTracks.concat(videoTracks);
599
+                                });
600
+                        } else {
601
+                            promise = createAudioTrack();
602
+                        }
603
+                    } else if (videoRequested && cameraDeviceId !== null) {
604
+                        promise = createVideoTrack();
605
+                    } else {
606
+                        promise = Promise.resolve([]);
607
+                    }
608
+
609
+                    return promise
610
+                        .then(onTracksCreated);
611
+
612
+                    function createAudioTrack(showError) {
613
+                        return createLocalTracks(['audio'], null, micDeviceId)
614
+                            .catch(err => {
615
+                                audioTrackCreationError = err;
616
+
617
+                                if (showError) {
618
+                                    APP.UI.showDeviceErrorDialog(err, null);
619
+                                }
620
+
621
+                                return [];
622
+                            });
623
+                    }
624
+
625
+                    function createVideoTrack(showError) {
626
+                        return createLocalTracks(
627
+                                ['video'], cameraDeviceId, null)
628
+                            .catch(err => {
629
+                                videoTrackCreationError = err;
630
+
631
+                                if (showError) {
632
+                                    APP.UI.showDeviceErrorDialog(null, err);
633
+                                }
634
+
635
+                                return [];
636
+                            });
637
+                    }
616 638
                 }
617 639
 
618 640
                 function onTracksCreated(tracks) {
@@ -1034,15 +1056,20 @@ export default {
1034 1056
                 // TrackErrors.CHROME_EXTENSION_INSTALLATION_ERROR
1035 1057
                 // TrackErrors.GENERAL
1036 1058
                 // and any other
1037
-                let dialogTxt = APP.translation.generateTranslationHTML(
1038
-                    err.name === TrackErrors.PERMISSION_DENIED
1039
-                        ? "dialog.screenSharingPermissionDeniedError"
1040
-                        : "dialog.failtoinstall");
1041
-
1042
-                let dialogTitle = APP.translation.generateTranslationHTML(
1043
-                    err.name === TrackErrors.PERMISSION_DENIED
1044
-                        ? "dialog.permissionDenied"
1045
-                        : "dialog.error");
1059
+                let dialogTxt;
1060
+                let dialogTitle;
1061
+
1062
+                if (err.name === TrackErrors.PERMISSION_DENIED) {
1063
+                    dialogTxt = APP.translation.generateTranslationHTML(
1064
+                        "dialog.screenSharingPermissionDeniedError");
1065
+                    dialogTitle = APP.translation.generateTranslationHTML(
1066
+                        "dialog.error");
1067
+                } else {
1068
+                    dialogTxt = APP.translation.generateTranslationHTML(
1069
+                        "dialog.failtoinstall");
1070
+                    dialogTitle = APP.translation.generateTranslationHTML(
1071
+                        "dialog.permissionDenied");
1072
+                }
1046 1073
 
1047 1074
                 APP.UI.messageHandler.openDialog(dialogTitle, dialogTxt, false);
1048 1075
             });
@@ -1404,7 +1431,7 @@ export default {
1404 1431
                         APP.settings.setCameraDeviceId(cameraDeviceId);
1405 1432
                     })
1406 1433
                     .catch((err) => {
1407
-                        APP.UI.showDeviceErrorDialog('camera', err);
1434
+                        APP.UI.showDeviceErrorDialog(null, err);
1408 1435
                         APP.UI.setSelectedCameraFromSettings();
1409 1436
                     });
1410 1437
             }
@@ -1420,7 +1447,7 @@ export default {
1420 1447
                         APP.settings.setMicDeviceId(micDeviceId);
1421 1448
                     })
1422 1449
                     .catch((err) => {
1423
-                        APP.UI.showDeviceErrorDialog('microphone', err);
1450
+                        APP.UI.showDeviceErrorDialog(err, null);
1424 1451
                         APP.UI.setSelectedMicFromSettings();
1425 1452
                     });
1426 1453
             }

+ 2
- 0
lang/main.json Vedi File

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

+ 100
- 31
modules/UI/UI.js Vedi File

@@ -1155,41 +1155,93 @@ UI.showExtensionRequiredDialog = function (url) {
1155 1155
 };
1156 1156
 
1157 1157
 /**
1158
- * Shows dialog with information about camera or microphone error.
1159
- * @param {'microphone'|'camera'} type
1160
- * @param {JitsiTrackError} error
1161
- */
1162
-UI.showDeviceErrorDialog = function (type, error) {
1163
-    if (type !== "microphone" && type !== "camera") {
1164
-        throw new Error("Invalid device type");
1158
+ * Shows dialog with combined information about camera and microphone errors.
1159
+ * @param {JitsiTrackError} micError
1160
+ * @param {JitsiTrackError} cameraError
1161
+ */
1162
+UI.showDeviceErrorDialog = function (micError, cameraError) {
1163
+    let localStoragePropName = "doNotShowErrorAgain";
1164
+    let isMicJitsiTrackErrorAndHasName = micError && micError.name &&
1165
+        micError instanceof JitsiMeetJS.JitsiTrackError;
1166
+    let isCameraJitsiTrackErrorAndHasName = cameraError && cameraError.name &&
1167
+        cameraError instanceof JitsiMeetJS.JitsiTrackError;
1168
+    let showDoNotShowWarning = false;
1169
+
1170
+    if (micError && cameraError && isMicJitsiTrackErrorAndHasName &&
1171
+        isCameraJitsiTrackErrorAndHasName) {
1172
+        showDoNotShowWarning =  true;
1173
+    } else if (micError && isMicJitsiTrackErrorAndHasName && !cameraError) {
1174
+        showDoNotShowWarning =  true;
1175
+    } else if (cameraError && isCameraJitsiTrackErrorAndHasName && !micError) {
1176
+        showDoNotShowWarning =  true;
1165 1177
     }
1166 1178
 
1167
-    if (error.name && error instanceof JitsiMeetJS.JitsiTrackError &&
1168
-        window.localStorage[type + "DoNotShowErrorAgain-" + error.name]
1169
-            === "true") {
1170
-        return;
1179
+    if (micError) {
1180
+        localStoragePropName += "-mic-" + micError.name;
1181
+    }
1182
+
1183
+    if (cameraError) {
1184
+        localStoragePropName += "-camera-" + cameraError.name;
1185
+    }
1186
+
1187
+    if (showDoNotShowWarning) {
1188
+        if (window.localStorage[localStoragePropName] === "true") {
1189
+            return;
1190
+        }
1191
+    }
1192
+
1193
+    let title = getTitleKey();
1194
+    let titleMsg = `<span data-i18n="${title}"></span>`;
1195
+    let cameraJitsiTrackErrorMsg = cameraError
1196
+        ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[cameraError.name]
1197
+        : undefined;
1198
+    let micJitsiTrackErrorMsg = micError
1199
+        ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[micError.name]
1200
+        : undefined;
1201
+    let cameraErrorMsg = cameraError
1202
+        ? cameraJitsiTrackErrorMsg ||
1203
+            JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.GENERAL]
1204
+        : "";
1205
+    let micErrorMsg = micError
1206
+        ? micJitsiTrackErrorMsg ||
1207
+            JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.GENERAL]
1208
+        : "";
1209
+    let additionalCameraErrorMsg = !cameraJitsiTrackErrorMsg && cameraError &&
1210
+        cameraError.message
1211
+            ? `<div>${cameraError.message}</div>`
1212
+            : ``;
1213
+    let additionalMicErrorMsg = !micJitsiTrackErrorMsg && micError &&
1214
+        micError.message
1215
+            ? `<div>${micError.message}</div>`
1216
+            : ``;
1217
+    let doNotShowWarningAgainSection = showDoNotShowWarning
1218
+        ? `<label>
1219
+            <input type='checkbox' id='doNotShowWarningAgain'> 
1220
+            <span data-i18n='dialog.doNotShowWarningAgain'></span>
1221
+           </label>`
1222
+        : ``;
1223
+    let message = '';
1224
+
1225
+    if (micError) {
1226
+        message = `
1227
+            ${message}
1228
+            <h3 data-i18n='dialog.micErrorPresent'></h3>
1229
+            <h4 data-i18n='${micErrorMsg}'></h4>
1230
+            ${additionalMicErrorMsg}`;
1171 1231
     }
1172 1232
 
1173
-    let titleKey = error.name === TrackErrors.PERMISSION_DENIED
1174
-            ? "dialog.permissionDenied"
1175
-            : "dialog.error",
1176
-        errorMsg = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP[type][error.name] ||
1177
-            JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP[type][TrackErrors.GENERAL],
1178
-        title = `<span data-i18n="${titleKey}"></span>`,
1179
-        message = "<h4 data-i18n='" + errorMsg + "'></h4>" +
1180
-            (!JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP[type][error.name]
1181
-            && error.message
1182
-                ? "<div>" + error.message + "</div>"
1183
-                : "") +
1184
-            "<label>" +
1185
-                "<input type='checkbox' id='doNotShowWarningAgain'> " +
1186
-                (error instanceof JitsiMeetJS.JitsiTrackError && error.name
1187
-                    ? "<span data-i18n='dialog.doNotShowWarningAgain'></span>"
1188
-                    : "") +
1189
-            "</label>";
1233
+    if (cameraError) {
1234
+        message = `
1235
+            ${message}
1236
+            <h3 data-i18n='dialog.cameraErrorPresent'></h3>
1237
+            <h4 data-i18n='${cameraErrorMsg}'></h4>
1238
+            ${additionalCameraErrorMsg}`;
1239
+    }
1240
+
1241
+    message = `${message}${doNotShowWarningAgainSection}`;
1190 1242
 
1191 1243
     messageHandler.openDialog(
1192
-        title,
1244
+        titleMsg,
1193 1245
         message,
1194 1246
         false,
1195 1247
         {Ok: true},
@@ -1200,14 +1252,31 @@ UI.showDeviceErrorDialog = function (type, error) {
1200 1252
                 let input = form.find("#doNotShowWarningAgain");
1201 1253
 
1202 1254
                 if (input.length) {
1203
-                    window.localStorage[type + "DoNotShowErrorAgain-"
1204
-                        + error.name] = input.prop("checked");
1255
+                    window.localStorage[localStoragePropName] =
1256
+                        input.prop("checked");
1205 1257
                 }
1206 1258
             }
1207 1259
         }
1208 1260
     );
1209 1261
 
1210 1262
     APP.translation.translateElement($(".jqibox"));
1263
+
1264
+    function getTitleKey() {
1265
+        let title = "dialog.error";
1266
+
1267
+        if (micError && micError.name === TrackErrors.PERMISSION_DENIED) {
1268
+            if (cameraError && cameraError.name === TrackErrors.PERMISSION_DENIED) {
1269
+                title = "dialog.permissionDenied";
1270
+            } else if (!cameraError) {
1271
+                title = "dialog.permissionDenied";
1272
+            }
1273
+        } else if (cameraError &&
1274
+            cameraError.name === TrackErrors.PERMISSION_DENIED) {
1275
+            title = "dialog.permissionDenied";
1276
+        }
1277
+
1278
+        return title;
1279
+    }
1211 1280
 };
1212 1281
 
1213 1282
 UI.updateDevicesAvailability = function (id, devices) {

Loading…
Annulla
Salva