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

middleware.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { NativeModules } from 'react-native';
  2. import { getAppProp } from '../../base/app/functions';
  3. import {
  4. CONFERENCE_BLURRED,
  5. CONFERENCE_FOCUSED,
  6. CONFERENCE_JOINED,
  7. CONFERENCE_LEFT,
  8. CONFERENCE_WILL_JOIN
  9. } from '../../base/conference/actionTypes';
  10. import { PARTICIPANT_JOINED } from '../../base/participants/actionTypes';
  11. import MiddlewareRegistry from '../../base/redux/MiddlewareRegistry';
  12. import StateListenerRegistry from '../../base/redux/StateListenerRegistry';
  13. import { READY_TO_CLOSE } from '../external-api/actionTypes';
  14. import { participantToParticipantInfo } from '../external-api/functions';
  15. import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture/actionTypes';
  16. import { isExternalAPIAvailable } from './functions';
  17. const externalAPIEnabled = isExternalAPIAvailable();
  18. const { JMOngoingConference } = NativeModules;
  19. /**
  20. * Check if native modules are being used or not.
  21. * If not, then the init of middleware doesn't happen.
  22. */
  23. !externalAPIEnabled && MiddlewareRegistry.register(store => next => action => {
  24. const result = next(action);
  25. const { type } = action;
  26. const rnSdkHandlers = getAppProp(store, 'rnSdkHandlers');
  27. switch (type) {
  28. case CONFERENCE_BLURRED:
  29. rnSdkHandlers?.onConferenceBlurred && rnSdkHandlers?.onConferenceBlurred();
  30. break;
  31. case CONFERENCE_FOCUSED:
  32. rnSdkHandlers?.onConferenceFocused && rnSdkHandlers?.onConferenceFocused();
  33. break;
  34. case CONFERENCE_JOINED:
  35. rnSdkHandlers?.onConferenceJoined && rnSdkHandlers?.onConferenceJoined();
  36. break;
  37. case CONFERENCE_LEFT:
  38. // Props are torn down at this point, perhaps need to leave this one out
  39. break;
  40. case CONFERENCE_WILL_JOIN:
  41. rnSdkHandlers?.onConferenceWillJoin && rnSdkHandlers?.onConferenceWillJoin();
  42. break;
  43. case ENTER_PICTURE_IN_PICTURE:
  44. rnSdkHandlers?.onEnterPictureInPicture && rnSdkHandlers?.onEnterPictureInPicture();
  45. break;
  46. case PARTICIPANT_JOINED: {
  47. const { participant } = action;
  48. const participantInfo = participantToParticipantInfo(participant);
  49. rnSdkHandlers?.onParticipantJoined && rnSdkHandlers?.onParticipantJoined(participantInfo);
  50. break;
  51. }
  52. case READY_TO_CLOSE:
  53. rnSdkHandlers?.onReadyToClose && rnSdkHandlers?.onReadyToClose();
  54. break;
  55. }
  56. return result;
  57. });
  58. /**
  59. * Check if native modules are being used or not.
  60. */
  61. !externalAPIEnabled && StateListenerRegistry.register(
  62. state => state['features/base/conference'].conference,
  63. (conference, previousConference) => {
  64. if (!conference) {
  65. JMOngoingConference.abort();
  66. } else if (conference && !previousConference) {
  67. JMOngoingConference.launch();
  68. } else if (conference !== previousConference) {
  69. JMOngoingConference.abort();
  70. JMOngoingConference.launch();
  71. }
  72. }
  73. );