You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.ts 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { Alert } from 'react-native';
  2. import { isRoomValid } from '../../base/conference/functions';
  3. import i18next from '../../base/i18n/i18next';
  4. import MiddlewareRegistry from '../../base/redux/MiddlewareRegistry';
  5. import { TRACK_CREATE_ERROR } from '../../base/tracks/actionTypes';
  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: string) {
  43. /* eslint-disable indent */
  44. const message = trackType === 'video'
  45. ? i18next.t('dialog.permissionCameraRequiredError')
  46. : i18next.t('dialog.permissionMicRequiredError');
  47. /* eslint-ensable indent */
  48. Alert.alert(
  49. i18next.t('dialog.permissionErrorTitle'),
  50. message,
  51. [
  52. { text: i18next.t('dialog.Cancel') },
  53. {
  54. onPress: openSettings,
  55. text: i18next.t('settings.title')
  56. }
  57. ],
  58. { cancelable: false });
  59. }