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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // @flow
  2. import { Share } from 'react-native';
  3. import { getName } from '../app';
  4. import { MiddlewareRegistry } from '../base/redux';
  5. import { endShareRoom } from './actions';
  6. import { BEGIN_SHARE_ROOM } from './actionTypes';
  7. const logger = require('jitsi-meet-logger').getLogger(__filename);
  8. /**
  9. * Middleware that captures room URL sharing actions and starts the sharing
  10. * process.
  11. *
  12. * @param {Store} store - Redux store.
  13. * @returns {Function}
  14. */
  15. MiddlewareRegistry.register(store => next => action => {
  16. switch (action.type) {
  17. case BEGIN_SHARE_ROOM:
  18. _shareRoom(action.roomURL, store.dispatch);
  19. break;
  20. }
  21. return next(action);
  22. });
  23. /**
  24. * Open the native sheet for sharing a specific conference/room URL.
  25. *
  26. * @param {string} roomURL - The URL of the conference/room to be shared.
  27. * @param {Dispatch} dispatch - The Redux dispatch function.
  28. * @private
  29. * @returns {void}
  30. */
  31. function _shareRoom(roomURL: string, dispatch: Function) {
  32. // TODO The following display/human-readable strings were submitted for
  33. // review before i18n was introduces in react/. However, I reviewed it
  34. // afterwards. Translate the display/human-readable strings.
  35. const message = `Click the following link to join the meeting: ${roomURL}`;
  36. const title = `${getName()} Conference`;
  37. const onFulfilled
  38. = (shared: boolean) => dispatch(endShareRoom(roomURL, shared));
  39. Share.share(
  40. /* content */ {
  41. message,
  42. title
  43. },
  44. /* options */ {
  45. dialogTitle: title, // Android
  46. subject: title // iOS
  47. })
  48. .then(
  49. /* onFulfilled */ value => {
  50. onFulfilled(value.action === Share.sharedAction);
  51. },
  52. /* onRejected */ reason => {
  53. logger.error(
  54. `Failed to share conference/room URL ${roomURL}:`,
  55. reason);
  56. onFulfilled(false);
  57. });
  58. }