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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. /**
  8. * Middleware that captures room URL sharing actions and starts the sharing
  9. * process.
  10. *
  11. * @param {Store} store - Redux store.
  12. * @returns {Function}
  13. */
  14. MiddlewareRegistry.register(store => next => action => {
  15. switch (action.type) {
  16. case BEGIN_SHARE_ROOM:
  17. _shareRoom(action.roomURL, store.dispatch);
  18. break;
  19. }
  20. return next(action);
  21. });
  22. /**
  23. * Open the native sheet for sharing a specific conference/room URL.
  24. *
  25. * @param {string} roomURL - The URL of the conference/room to be shared.
  26. * @param {Dispatch} dispatch - The Redux dispatch function.
  27. * @private
  28. * @returns {void}
  29. */
  30. function _shareRoom(roomURL: string, dispatch: Function) {
  31. // TODO The following display/human-readable strings were submitted for
  32. // review before i18n was introduces in react/. However, I reviewed it
  33. // afterwards. Translate the display/human-readable strings.
  34. const message = `Click the following link to join the meeting: ${roomURL}`;
  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. console.error(
  53. `Failed to share conference/room URL ${roomURL}:`,
  54. reason);
  55. onFulfilled(false);
  56. });
  57. }