Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

middleware.ts 2.1KB

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