12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- /* @flow */
-
- import { Alert, Linking, NativeModules } from 'react-native';
-
- import { isRoomValid } from '../../base/conference';
- import { Platform } from '../../base/react';
- import { MiddlewareRegistry } from '../../base/redux';
- import { TRACK_PERMISSION_ERROR } from '../../base/tracks';
-
- /**
- * Middleware that captures track permission errors and alerts the user so they
- * can enable the permission themselves.
- *
- * @param {Store} store - The redux store.
- * @returns {Function}
- */
- MiddlewareRegistry.register(store => next => action => {
- const result = next(action);
-
- switch (action.type) {
- case TRACK_PERMISSION_ERROR:
- // XXX We do not currently have user interface outside of a conference
- // which the user may tap and cause a permission-related error. If we
- // alert whenever we (intend to) ask for a permission, the scenario of
- // entering the WelcomePage, being asked for the camera permission, me
- // denying it, and being alerted that there is an error is overwhelming
- // me.
- if (isRoomValid(store.getState()['features/base/conference'].room)) {
- _alertPermissionErrorWithSettings(action.trackType);
- }
- break;
- }
-
- return result;
- });
-
- /**
- * Shows an alert panel which tells the user they have to manually grant some
- * permissions by opening Settings. A button which opens Settings is provided.
- *
- * @param {string} trackType - Type of track that failed with a permission
- * error.
- * @private
- * @returns {void}
- */
- function _alertPermissionErrorWithSettings(trackType) {
- // TODO i18n
- const deviceType = trackType === 'video' ? 'Camera' : 'Microphone';
-
- /* eslint-disable indent */
-
- const message
- = `${deviceType
- } permission is required to participate in conferences with ${
- trackType}. Please grant it in Settings.`;
-
- /* eslint-ensable indent */
-
- Alert.alert(
- 'Permission required',
- message,
- [
- { text: 'Cancel' },
- {
- onPress: _openSettings,
- text: 'Settings'
- }
- ],
- { cancelable: false });
- }
-
- /**
- * Opens the settings panel for the current platform.
- *
- * @private
- * @returns {void}
- */
- function _openSettings() {
- switch (Platform.OS) {
- case 'android':
- NativeModules.AndroidSettings.open();
- break;
-
- case 'ios':
- Linking.openURL('app-settings:');
- break;
- }
- }
|