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.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // @flow
  2. import { Share } from 'react-native';
  3. import { getName } from '../app';
  4. import { MiddlewareRegistry } from '../base/redux';
  5. import { getShareInfoText } from '../invite';
  6. import { endShareRoom } from './actions';
  7. import { BEGIN_SHARE_ROOM } from './actionTypes';
  8. const logger = require('jitsi-meet-logger').getLogger(__filename);
  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, action.includeDialInfo, store.dispatch);
  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 {boolean} includeDialInfo - Whether to include or not the dialing
  29. * information link.
  30. * @param {Dispatch} dispatch - The Redux dispatch function.
  31. * @private
  32. * @returns {void}
  33. */
  34. function _shareRoom(
  35. roomURL: string, includeDialInfo: boolean, dispatch: Function) {
  36. const message = getShareInfoText(roomURL, includeDialInfo);
  37. const title = `${getName()} Conference`;
  38. const onFulfilled
  39. = (shared: boolean) => dispatch(endShareRoom(roomURL, shared));
  40. Share.share(
  41. /* content */ {
  42. message,
  43. title
  44. },
  45. /* options */ {
  46. dialogTitle: title, // Android
  47. subject: title // iOS
  48. })
  49. .then(
  50. /* onFulfilled */ value => {
  51. onFulfilled(value.action === Share.sharedAction);
  52. },
  53. /* onRejected */ reason => {
  54. logger.error(
  55. `Failed to share conference/room URL ${roomURL}:`,
  56. reason);
  57. onFulfilled(false);
  58. });
  59. }