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

middleware.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // @flow
  2. import { Share } from 'react-native';
  3. import { getName } from '../app/functions';
  4. import { MiddlewareRegistry } from '../base/redux';
  5. import { getShareInfoText } from '../invite';
  6. import { BEGIN_SHARE_ROOM } from './actionTypes';
  7. import { endShareRoom } 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 }) {
  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. },
  51. /* onRejected */ reason => {
  52. logger.error(
  53. `Failed to share conference/room URL ${roomURL}:`,
  54. reason);
  55. onFulfilled(false);
  56. });
  57. });
  58. }