您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* @flow */
  2. import { NativeModules } from 'react-native';
  3. import { getInviteURL } from '../../base/connection';
  4. import {
  5. CONFERENCE_FAILED,
  6. CONFERENCE_JOINED,
  7. CONFERENCE_LEFT,
  8. CONFERENCE_WILL_JOIN,
  9. CONFERENCE_WILL_LEAVE
  10. } from '../../base/conference';
  11. import { MiddlewareRegistry } from '../../base/redux';
  12. /**
  13. * Middleware that captures Redux actions and uses the ExternalAPI module to
  14. * turn them into native events so the application knows about them.
  15. *
  16. * @param {Store} store - Redux store.
  17. * @returns {Function}
  18. */
  19. MiddlewareRegistry.register(store => next => action => {
  20. const eventData = {};
  21. switch (action.type) {
  22. case CONFERENCE_FAILED: {
  23. eventData.error = action.error;
  24. eventData.url = getInviteURL(store.getState());
  25. _sendEvent('CONFERENCE_FAILED', eventData);
  26. break;
  27. }
  28. case CONFERENCE_JOINED: {
  29. eventData.url = getInviteURL(store.getState());
  30. _sendEvent('CONFERENCE_JOINED', eventData);
  31. break;
  32. }
  33. case CONFERENCE_LEFT: {
  34. eventData.url = getInviteURL(store.getState());
  35. _sendEvent('CONFERENCE_LEFT', eventData);
  36. break;
  37. }
  38. case CONFERENCE_WILL_JOIN: {
  39. eventData.url = getInviteURL(store.getState());
  40. _sendEvent('CONFERENCE_WILL_JOIN', eventData);
  41. break;
  42. }
  43. case CONFERENCE_WILL_LEAVE: {
  44. eventData.url = getInviteURL(store.getState());
  45. _sendEvent('CONFERENCE_WILL_LEAVE', eventData);
  46. break;
  47. }
  48. }
  49. return next(action);
  50. });
  51. /**
  52. * Sends the given event to the native side of the application. Applications can
  53. * then listen to the events using the mechanisms provided by the Jitsi Meet
  54. * SDK.
  55. *
  56. * @param {string} name - Event name.
  57. * @param {Object} data - Ancillary data for the event.
  58. * @private
  59. * @returns {void}
  60. */
  61. function _sendEvent(name: string, data: Object) {
  62. NativeModules.ExternalAPI.sendEvent(name, data);
  63. }