浏览代码

[RN] Remove denied permission alert from WelcomePage

master
Lyubo Marinov 8 年前
父节点
当前提交
24db52ef0f

+ 50
- 13
react/features/base/tracks/actions.js 查看文件

@@ -83,19 +83,10 @@ export function createLocalTracksA(options = {}) {
83 83
                 },
84 84
                 /* firePermissionPromptIsShownEvent */ false,
85 85
                 store)
86
-            .then(localTracks => dispatch(_updateLocalTracks(localTracks)))
87
-            .catch(({ gum }) => {
88
-                // If permissions are not allowed, alert the user.
89
-                if (gum
90
-                        && gum.error
91
-                        && gum.error.name === 'DOMException'
92
-                        && gum.error.message === 'NotAllowedError') {
93
-                    dispatch({
94
-                        type: TRACK_PERMISSION_ERROR,
95
-                        trackType: device
96
-                    });
97
-                }
98
-            });
86
+            .then(
87
+                localTracks => dispatch(_updateLocalTracks(localTracks)),
88
+                reason =>
89
+                    dispatch(_onCreateLocalTracksRejected(reason, device)));
99 90
         }
100 91
     };
101 92
 }
@@ -390,6 +381,52 @@ function _getLocalTracksToChange(currentTracks, newTracks) {
390 381
     };
391 382
 }
392 383
 
384
+/**
385
+ * Implements the <tt>Promise</tt> rejection handler of
386
+ * <tt>createLocalTracksA</tt> and <tt>createLocalTracksF</tt>.
387
+ *
388
+ * @param {Object} reason - The <tt>Promise</tt> rejection reason.
389
+ * @param {string} device - The device/<tt>MEDIA_TYPE</tt> associated with the
390
+ * rejection.
391
+ * @private
392
+ * @returns {Function}
393
+ */
394
+function _onCreateLocalTracksRejected({ gum }, device) {
395
+    return dispatch => {
396
+        // If permissions are not allowed, alert the user.
397
+        if (gum) {
398
+            const { error } = gum;
399
+
400
+            if (error) {
401
+                // FIXME For whatever reason (which is probably an
402
+                // implementation fault), react-native-webrtc will give the
403
+                // error in one of the following formats depending on whether it
404
+                // is attached to a remote debugger or not. (The remote debugger
405
+                // scenario suggests that react-native-webrtc is at fault
406
+                // because the remote debugger is Google Chrome and then its
407
+                // JavaScript engine will define DOMException. I suspect I wrote
408
+                // react-native-webrtc to return the error in the alternative
409
+                // format if DOMException is not defined.)
410
+                let trackPermissionError;
411
+
412
+                switch (error.name) {
413
+                case 'DOMException':
414
+                    trackPermissionError = error.message === 'NotAllowedError';
415
+                    break;
416
+
417
+                case 'NotAllowedError':
418
+                    trackPermissionError = error instanceof DOMException;
419
+                    break;
420
+                }
421
+                trackPermissionError && dispatch({
422
+                    type: TRACK_PERMISSION_ERROR,
423
+                    trackType: device
424
+                });
425
+            }
426
+        }
427
+    };
428
+}
429
+
393 430
 /**
394 431
  * Returns true if the provided JitsiTrack should be rendered as a mirror.
395 432
  *

+ 0
- 47
react/features/mobile/permissions/functions.js 查看文件

@@ -1,47 +0,0 @@
1
-import { Alert, Linking, NativeModules } from 'react-native';
2
-
3
-import { Platform } from '../../base/react';
4
-
5
-/**
6
- * Shows an alert panel which tells the user they have to manually grant some
7
- * permissions by opening Settings. A button which opens Settings is provided.
8
- *
9
- * FIXME: translate.
10
- *
11
- * @param {string} trackType - Type of track that failed with a permission
12
- * error.
13
- * @returns {void}
14
- */
15
-export function alertPermissionErrorWithSettings(trackType) {
16
-    const type = trackType === 'video' ? 'Camera' : 'Microphone';
17
-
18
-    Alert.alert(
19
-        'Permissions Error',
20
-        `${type} permission is required, please enable it in Settings.`,
21
-        [
22
-            { text: 'Cancel' },
23
-            {
24
-                onPress: _openSettings,
25
-                text: 'Settings'
26
-            }
27
-        ],
28
-        { cancelable: false });
29
-}
30
-
31
-/**
32
- * Opens the settings panel for the current platform.
33
- *
34
- * @private
35
- * @returns {void}
36
- */
37
-function _openSettings() {
38
-    switch (Platform.OS) {
39
-    case 'android':
40
-        NativeModules.AndroidSettings.open();
41
-        break;
42
-
43
-    case 'ios':
44
-        Linking.openURL('app-settings:');
45
-        break;
46
-    }
47
-}

+ 60
- 4
react/features/mobile/permissions/middleware.js 查看文件

@@ -1,10 +1,12 @@
1 1
 /* @flow */
2 2
 
3
+import { Alert, Linking, NativeModules } from 'react-native';
4
+
5
+import { isRoomValid } from '../../base/conference';
6
+import { Platform } from '../../base/react';
3 7
 import { MiddlewareRegistry } from '../../base/redux';
4 8
 import { TRACK_PERMISSION_ERROR } from '../../base/tracks';
5 9
 
6
-import { alertPermissionErrorWithSettings } from './functions';
7
-
8 10
 /**
9 11
  * Middleware that captures track permission errors and alerts the user so they
10 12
  * can enable the permission themselves.
@@ -12,14 +14,68 @@ import { alertPermissionErrorWithSettings } from './functions';
12 14
  * @param {Store} store - The redux store.
13 15
  * @returns {Function}
14 16
  */
15
-MiddlewareRegistry.register(() => next => action => {
17
+MiddlewareRegistry.register(store => next => action => {
16 18
     const result = next(action);
17 19
 
18 20
     switch (action.type) {
19 21
     case TRACK_PERMISSION_ERROR:
20
-        alertPermissionErrorWithSettings(action.trackType);
22
+        // XXX We do not currently have user interface outside of a conference
23
+        // which the user may tap and cause a permission-related error. If we
24
+        // alert whenever we (intend to) ask for a permission, the scenario of
25
+        // entering the WelcomePage, being asked for the camera permission, me
26
+        // denying it, and being alerted that there is an error is overwhelming
27
+        // me.
28
+        if (isRoomValid(store.getState()['features/base/conference'].room)) {
29
+            _alertPermissionErrorWithSettings(action.trackType);
30
+        }
21 31
         break;
22 32
     }
23 33
 
24 34
     return result;
25 35
 });
36
+
37
+/**
38
+ * Shows an alert panel which tells the user they have to manually grant some
39
+ * permissions by opening Settings. A button which opens Settings is provided.
40
+ *
41
+ * @param {string} trackType - Type of track that failed with a permission
42
+ * error.
43
+ * @private
44
+ * @returns {void}
45
+ */
46
+function _alertPermissionErrorWithSettings(trackType) {
47
+    // TODO i18n
48
+    const deviceType = trackType === 'video' ? 'Camera' : 'Microphone';
49
+
50
+    Alert.alert(
51
+        'Permission required',
52
+        `${deviceType
53
+            } permission is required to participate in conferences with ${
54
+            trackType}. Please grant it in Settings.`,
55
+        [
56
+            { text: 'Cancel' },
57
+            {
58
+                onPress: _openSettings,
59
+                text: 'Settings'
60
+            }
61
+        ],
62
+        { cancelable: false });
63
+}
64
+
65
+/**
66
+ * Opens the settings panel for the current platform.
67
+ *
68
+ * @private
69
+ * @returns {void}
70
+ */
71
+function _openSettings() {
72
+    switch (Platform.OS) {
73
+    case 'android':
74
+        NativeModules.AndroidSettings.open();
75
+        break;
76
+
77
+    case 'ios':
78
+        Linking.openURL('app-settings:');
79
+        break;
80
+    }
81
+}

正在加载...
取消
保存