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

middleware.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* @flow */
  2. import { Alert } from 'react-native';
  3. import { isRoomValid } from '../../base/conference';
  4. import { MiddlewareRegistry } from '../../base/redux';
  5. import { TRACK_CREATE_ERROR } from '../../base/tracks';
  6. import { openSettings } from './functions';
  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_CREATE_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 (action.permissionDenied
  25. && isRoomValid(
  26. store.getState()['features/base/conference'].room)) {
  27. _alertPermissionErrorWithSettings(action.trackType);
  28. }
  29. break;
  30. }
  31. return result;
  32. });
  33. /**
  34. * Shows an alert panel which tells the user they have to manually grant some
  35. * permissions by opening Settings. A button which opens Settings is provided.
  36. *
  37. * @param {string} trackType - Type of track that failed with a permission
  38. * error.
  39. * @private
  40. * @returns {void}
  41. */
  42. function _alertPermissionErrorWithSettings(trackType) {
  43. // TODO i18n
  44. const deviceType = trackType === 'video' ? 'Camera' : 'Microphone';
  45. /* eslint-disable indent */
  46. const message
  47. = `${deviceType
  48. } permission is required to participate in conferences with ${
  49. trackType}. Please grant it in Settings.`;
  50. /* eslint-ensable indent */
  51. Alert.alert(
  52. 'Permission required',
  53. message,
  54. [
  55. { text: 'Cancel' },
  56. {
  57. onPress: openSettings,
  58. text: 'Settings'
  59. }
  60. ],
  61. { cancelable: false });
  62. }