|
@@ -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
|
+}
|