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. /* @flow */
  2. import { NativeModules } from 'react-native';
  3. import { APP_WILL_MOUNT } from '../../app';
  4. import {
  5. CONFERENCE_FAILED,
  6. CONFERENCE_LEFT,
  7. CONFERENCE_WILL_JOIN,
  8. SET_AUDIO_ONLY
  9. } from '../../base/conference';
  10. import { MiddlewareRegistry } from '../../base/redux';
  11. /**
  12. * Middleware that captures conference actions and sets the correct audio mode
  13. * based on the type of conference. Audio-only conferences don't use the speaker
  14. * by default, and video conferences do.
  15. *
  16. * @param {Store} store - The redux store.
  17. * @returns {Function}
  18. */
  19. MiddlewareRegistry.register(({ getState }) => next => action => {
  20. const AudioMode = NativeModules.AudioMode;
  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. case SET_AUDIO_ONLY: {
  31. if (getState()['features/base/conference'].conference
  32. || action.conference) {
  33. mode
  34. = action.audioOnly
  35. ? AudioMode.AUDIO_CALL
  36. : AudioMode.VIDEO_CALL;
  37. }
  38. break;
  39. }
  40. }
  41. if (typeof mode !== 'undefined') {
  42. AudioMode.setMode(mode)
  43. .catch(err =>
  44. console.error(
  45. `Failed to set audio mode ${String(mode)}: ${err}`));
  46. }
  47. }
  48. return next(action);
  49. });