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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 } 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 READY_TO_CLOSE:
  60. rnSdkHandlers?.onReadyToClose && rnSdkHandlers?.onReadyToClose();
  61. break;
  62. }
  63. return result;
  64. });
  65. /**
  66. * Before enabling media projection service control on Android,
  67. * we need to check if native modules are being used or not.
  68. */
  69. Platform.OS === 'android' && !externalAPIEnabled && StateListenerRegistry.register(
  70. state => state['features/base/conference'].conference,
  71. (conference, previousConference) => {
  72. if (!conference) {
  73. JMOngoingConference.abort();
  74. } else if (conference && !previousConference) {
  75. JMOngoingConference.launch();
  76. } else if (conference !== previousConference) {
  77. JMOngoingConference.abort();
  78. JMOngoingConference.launch();
  79. }
  80. }
  81. );