Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

middleware.js 3.6KB

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