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.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { Share } from 'react-native';
  2. import { getName } from '../app/functions.native';
  3. import { IStore } from '../app/types';
  4. import { INVITE_DIAL_IN_ENABLED } from '../base/flags/constants';
  5. import { getFeatureFlag } from '../base/flags/functions';
  6. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  7. import { getShareInfoText } from '../invite/functions';
  8. import { BEGIN_SHARE_ROOM } from './actionTypes';
  9. import { endShareRoom, toggleShareDialog } from './actions';
  10. import logger from './logger';
  11. /**
  12. * Middleware that captures room URL sharing actions and starts the sharing
  13. * process.
  14. *
  15. * @param {Store} store - Redux store.
  16. * @returns {Function}
  17. */
  18. MiddlewareRegistry.register(store => next => action => {
  19. switch (action.type) {
  20. case BEGIN_SHARE_ROOM:
  21. _shareRoom(action.roomURL, store);
  22. break;
  23. }
  24. return next(action);
  25. });
  26. /**
  27. * Open the native sheet for sharing a specific conference/room URL.
  28. *
  29. * @param {string} roomURL - The URL of the conference/room to be shared.
  30. * @param {Store} store - Redux store.
  31. * @private
  32. * @returns {void}
  33. */
  34. function _shareRoom(roomURL: string, { dispatch, getState }: IStore) {
  35. const dialInEnabled = getFeatureFlag(getState(), INVITE_DIAL_IN_ENABLED, true);
  36. getShareInfoText(getState(), roomURL, false /* useHtml */, !dialInEnabled /* skipDialIn */)
  37. .then(message => {
  38. const title = `${getName()} Conference`;
  39. const onFulfilled
  40. = (shared: boolean) => dispatch(endShareRoom(roomURL, shared));
  41. Share.share(
  42. /* content */ {
  43. message,
  44. title
  45. },
  46. /* options */ {
  47. dialogTitle: title, // Android
  48. subject: title // iOS
  49. })
  50. .then(
  51. /* onFulfilled */ value => {
  52. onFulfilled(value.action === Share.sharedAction);
  53. },
  54. /* onRejected */ reason => {
  55. logger.error(
  56. `Failed to share conference/room URL ${roomURL}:`,
  57. reason);
  58. onFulfilled(false);
  59. })
  60. .finally(() => {
  61. dispatch(toggleShareDialog(false));
  62. });
  63. });
  64. }