您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 2.4KB

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