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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* @flow */
  2. import { NativeModules } from 'react-native';
  3. import {
  4. CONFERENCE_FAILED,
  5. CONFERENCE_JOINED,
  6. CONFERENCE_LEFT,
  7. CONFERENCE_WILL_JOIN,
  8. CONFERENCE_WILL_LEAVE
  9. } from '../../base/conference';
  10. import { MiddlewareRegistry } from '../../base/redux';
  11. /**
  12. * Middleware that captures Redux actions and uses the ExternalAPI module to
  13. * turn them into native events so the application knows about them.
  14. *
  15. * @param {Store} store - Redux store.
  16. * @returns {Function}
  17. */
  18. MiddlewareRegistry.register(store => next => action => {
  19. const result = next(action);
  20. switch (action.type) {
  21. case CONFERENCE_FAILED:
  22. case CONFERENCE_JOINED:
  23. case CONFERENCE_LEFT:
  24. case CONFERENCE_WILL_JOIN:
  25. case CONFERENCE_WILL_LEAVE: {
  26. const { conference, room, type, ...data } = action;
  27. // For the above (redux) actions, conference and/or room identify a
  28. // JitsiConference instance. The external API cannot transport such an
  29. // object so we have to transport an "equivalent".
  30. if (conference || room) {
  31. // We have chosen to identify the object in question by the
  32. // (supposedly) associated location URL. (FIXME Actually, the redux
  33. // state locationURL is not really asssociated with the
  34. // JitsiConference instance. The value of localtionURL is utilized
  35. // in order to initialize the JitsiConference instance but the value
  36. // of locationURL at the time of CONFERENCE_WILL_LEAVE and
  37. // CONFERENCE_LEFT will not be the value with which the
  38. // JitsiConference instance being left.)
  39. const { locationURL }
  40. = store.getState()['features/base/connection'];
  41. if (!locationURL) {
  42. // The (redux) action cannot be fully converted to an (external
  43. // API) event.
  44. break;
  45. }
  46. data.url = locationURL.href;
  47. }
  48. // The (externa API) event's name is the string representation of the
  49. // (redux) action's type.
  50. let name = type.toString();
  51. // XXX We are using Symbol for (redux) action types at the time of this
  52. // writing so the Symbol's description should be used.
  53. if (name.startsWith('Symbol(') && name.endsWith(')')) {
  54. name = name.slice(7, -1);
  55. }
  56. _sendEvent(name, data);
  57. break;
  58. }
  59. }
  60. return result;
  61. });
  62. /**
  63. * Sends a specific event to the native counterpart of the External API. Native
  64. * apps may listen to such events via the mechanisms provided by the (native)
  65. * mobile Jitsi Meet SDK.
  66. *
  67. * @param {string} name - The name of the event to send.
  68. * @param {Object} data - The details/specifics of the event to send determined
  69. * by/associated with the specified {@code name}.
  70. * @private
  71. * @returns {void}
  72. */
  73. function _sendEvent(name: string, data: Object) {
  74. NativeModules.ExternalAPI.sendEvent(name, data);
  75. }