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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. ENDPOINT_MESSAGE_RECEIVED
  10. } from '../../base/conference/actionTypes';
  11. import { SET_AUDIO_MUTED, SET_VIDEO_MUTED } from '../../base/media/actionTypes';
  12. import { PARTICIPANT_JOINED, PARTICIPANT_LEFT } from '../../base/participants/actionTypes';
  13. import MiddlewareRegistry from '../../base/redux/MiddlewareRegistry';
  14. import StateListenerRegistry from '../../base/redux/StateListenerRegistry';
  15. import { READY_TO_CLOSE } from '../external-api/actionTypes';
  16. import { participantToParticipantInfo } from '../external-api/functions';
  17. import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture/actionTypes';
  18. import { isExternalAPIAvailable } from './functions';
  19. const externalAPIEnabled = isExternalAPIAvailable();
  20. const { JMOngoingConference } = NativeModules;
  21. /**
  22. * Check if native modules are being used or not.
  23. * If not, then the init of middleware doesn't happen.
  24. */
  25. !externalAPIEnabled && MiddlewareRegistry.register(store => next => action => {
  26. const result = next(action);
  27. const { type } = action;
  28. const rnSdkHandlers = getAppProp(store, 'rnSdkHandlers');
  29. switch (type) {
  30. case SET_AUDIO_MUTED:
  31. rnSdkHandlers?.onAudioMutedChanged?.(action.muted);
  32. break;
  33. case SET_VIDEO_MUTED:
  34. rnSdkHandlers?.onVideoMutedChanged?.(Boolean(action.muted));
  35. break;
  36. case CONFERENCE_BLURRED:
  37. rnSdkHandlers?.onConferenceBlurred?.();
  38. break;
  39. case CONFERENCE_FOCUSED:
  40. rnSdkHandlers?.onConferenceFocused?.();
  41. break;
  42. case CONFERENCE_JOINED:
  43. rnSdkHandlers?.onConferenceJoined?.();
  44. break;
  45. case CONFERENCE_LEFT:
  46. // Props are torn down at this point, perhaps need to leave this one out
  47. break;
  48. case CONFERENCE_WILL_JOIN:
  49. rnSdkHandlers?.onConferenceWillJoin?.();
  50. break;
  51. case ENTER_PICTURE_IN_PICTURE:
  52. rnSdkHandlers?.onEnterPictureInPicture?.();
  53. break;
  54. case ENDPOINT_MESSAGE_RECEIVED: {
  55. const { data, participant } = action;
  56. rnSdkHandlers?.onEndpointMessageReceived?.({
  57. data,
  58. participant
  59. });
  60. break;
  61. }
  62. case PARTICIPANT_JOINED: {
  63. const { participant } = action;
  64. const participantInfo = participantToParticipantInfo(participant);
  65. rnSdkHandlers?.onParticipantJoined?.(participantInfo);
  66. break;
  67. }
  68. case PARTICIPANT_LEFT: {
  69. const { participant } = action;
  70. const { id } = participant ?? {};
  71. rnSdkHandlers?.onParticipantLeft?.({ id });
  72. break;
  73. }
  74. case READY_TO_CLOSE:
  75. rnSdkHandlers?.onReadyToClose?.();
  76. break;
  77. }
  78. return result;
  79. });
  80. /**
  81. * Before enabling media projection service control on Android,
  82. * we need to check if native modules are being used or not.
  83. */
  84. JMOngoingConference && !externalAPIEnabled && StateListenerRegistry.register(
  85. state => state['features/base/conference'].conference,
  86. (conference, previousConference) => {
  87. if (!conference) {
  88. JMOngoingConference.abort();
  89. } else if (conference && !previousConference) {
  90. JMOngoingConference.launch();
  91. } else if (conference !== previousConference) {
  92. JMOngoingConference.abort();
  93. JMOngoingConference.launch();
  94. }
  95. }
  96. );