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

middleware.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. Alert.alert(
  44. 'Permission required',
  45. `${deviceType
  46. } permission is required to participate in conferences with ${
  47. trackType}. Please grant it in Settings.`,
  48. [
  49. { text: 'Cancel' },
  50. {
  51. onPress: _openSettings,
  52. text: 'Settings'
  53. }
  54. ],
  55. { cancelable: false });
  56. }
  57. /**
  58. * Opens the settings panel for the current platform.
  59. *
  60. * @private
  61. * @returns {void}
  62. */
  63. function _openSettings() {
  64. switch (Platform.OS) {
  65. case 'android':
  66. NativeModules.AndroidSettings.open();
  67. break;
  68. case 'ios':
  69. Linking.openURL('app-settings:');
  70. break;
  71. }
  72. }