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.8KB

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