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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { NativeModules } from 'react-native';
  2. import { APP_WILL_MOUNT } from '../app';
  3. import {
  4. CONFERENCE_FAILED,
  5. CONFERENCE_LEFT,
  6. CONFERENCE_WILL_JOIN
  7. } from '../base/conference';
  8. import { MiddlewareRegistry } from '../base/redux';
  9. /**
  10. * Middleware that captures conference actions and sets the correct audio mode
  11. * based on the type of conference. Audio-only conferences don't use the speaker
  12. * by default, and video conferences do.
  13. *
  14. * @param {Store} store - Redux store.
  15. * @returns {Function}
  16. */
  17. MiddlewareRegistry.register(store => next => action => {
  18. const AudioMode = NativeModules.AudioMode;
  19. // The react-native module AudioMode is implemented on iOS at the time of
  20. // this writing.
  21. if (AudioMode) {
  22. let mode;
  23. switch (action.type) {
  24. case APP_WILL_MOUNT:
  25. case CONFERENCE_FAILED:
  26. case CONFERENCE_LEFT:
  27. mode = AudioMode.DEFAULT;
  28. break;
  29. case CONFERENCE_WILL_JOIN: {
  30. const conference = store.getState()['features/base/conference'];
  31. mode
  32. = conference.audioOnly
  33. ? AudioMode.AUDIO_CALL
  34. : AudioMode.VIDEO_CALL;
  35. break;
  36. }
  37. default:
  38. mode = null;
  39. break;
  40. }
  41. if (mode !== null) {
  42. AudioMode.setMode(mode)
  43. .catch(err =>
  44. console.error(`Failed to set audio mode ${mode}: ${err}`));
  45. }
  46. }
  47. return next(action);
  48. });