Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

middleware.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* @flow */
  2. import { Alert } from 'react-native';
  3. import { isRoomValid } from '../../base/conference';
  4. import { i18next } from '../../base/i18n';
  5. import { MiddlewareRegistry } from '../../base/redux';
  6. import { TRACK_CREATE_ERROR } from '../../base/tracks';
  7. import { openSettings } from './functions';
  8. /**
  9. * Middleware that captures track permission errors and alerts the user so they
  10. * can enable the permission themselves.
  11. *
  12. * @param {Store} store - The redux store.
  13. * @returns {Function}
  14. */
  15. MiddlewareRegistry.register(store => next => action => {
  16. const result = next(action);
  17. switch (action.type) {
  18. case TRACK_CREATE_ERROR:
  19. // XXX We do not currently have user interface outside of a conference
  20. // which the user may tap and cause a permission-related error. If we
  21. // alert whenever we (intend to) ask for a permission, the scenario of
  22. // entering the WelcomePage, being asked for the camera permission, me
  23. // denying it, and being alerted that there is an error is overwhelming
  24. // me.
  25. if (action.permissionDenied
  26. && isRoomValid(
  27. store.getState()['features/base/conference'].room)) {
  28. _alertPermissionErrorWithSettings(action.trackType);
  29. }
  30. break;
  31. }
  32. return result;
  33. });
  34. /**
  35. * Shows an alert panel which tells the user they have to manually grant some
  36. * permissions by opening Settings. A button which opens Settings is provided.
  37. *
  38. * @param {string} trackType - Type of track that failed with a permission
  39. * error.
  40. * @private
  41. * @returns {void}
  42. */
  43. function _alertPermissionErrorWithSettings(trackType) {
  44. /* eslint-disable indent */
  45. const message = trackType === 'video'
  46. ? i18next.t('dialog.permissionCameraRequiredError')
  47. : i18next.t('dialog.permissionMicRequiredError');
  48. /* eslint-ensable indent */
  49. Alert.alert(
  50. i18next.t('dialog.permissionErrorTitle'),
  51. message,
  52. [
  53. { text: i18next.t('dialog.Cancel') },
  54. {
  55. onPress: openSettings,
  56. text: i18next.t('settings.title')
  57. }
  58. ],
  59. { cancelable: false });
  60. }