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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { getAppProp } from '../../base/app/functions';
  2. import {
  3. CONFERENCE_JOINED,
  4. CONFERENCE_LEFT,
  5. CONFERENCE_WILL_JOIN
  6. } from '../../base/conference/actionTypes';
  7. import { PARTICIPANT_JOINED } from '../../base/participants/actionTypes';
  8. import MiddlewareRegistry from '../../base/redux/MiddlewareRegistry';
  9. import { READY_TO_CLOSE } from '../external-api/actionTypes';
  10. import { participantToParticipantInfo } from '../external-api/functions';
  11. import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture/actionTypes';
  12. import { isExternalAPIAvailable } from './functions';
  13. const externalAPIEnabled = isExternalAPIAvailable();
  14. /**
  15. * Check if native modules are being used or not. If not then the init of middleware doesn't happen.
  16. */
  17. !externalAPIEnabled && MiddlewareRegistry.register(store => next => action => {
  18. const result = next(action);
  19. const { type } = action;
  20. const rnSdkHandlers = getAppProp(store, 'rnSdkHandlers');
  21. switch (type) {
  22. case CONFERENCE_JOINED:
  23. rnSdkHandlers?.onConferenceJoined && rnSdkHandlers?.onConferenceJoined();
  24. break;
  25. case CONFERENCE_LEFT:
  26. // Props are torn down at this point, perhaps need to leave this one out
  27. break;
  28. case CONFERENCE_WILL_JOIN:
  29. rnSdkHandlers?.onConferenceWillJoin && rnSdkHandlers?.onConferenceWillJoin();
  30. break;
  31. case ENTER_PICTURE_IN_PICTURE:
  32. rnSdkHandlers?.onEnterPictureInPicture && rnSdkHandlers?.onEnterPictureInPicture();
  33. break;
  34. case PARTICIPANT_JOINED: {
  35. const { participant } = action;
  36. const participantInfo = participantToParticipantInfo(participant);
  37. rnSdkHandlers?.onParticipantJoined && rnSdkHandlers?.onParticipantJoined(participantInfo);
  38. break;
  39. }
  40. case READY_TO_CLOSE:
  41. rnSdkHandlers?.onReadyToClose && rnSdkHandlers?.onReadyToClose();
  42. break;
  43. }
  44. return result;
  45. }
  46. );