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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* @flow */
  2. import { NativeModules } from 'react-native';
  3. import { APP_WILL_MOUNT } from '../../base/app';
  4. import {
  5. CONFERENCE_FAILED,
  6. CONFERENCE_LEFT,
  7. CONFERENCE_JOINED,
  8. SET_AUDIO_ONLY
  9. } from '../../base/conference';
  10. import { MiddlewareRegistry } from '../../base/redux';
  11. const AudioMode = NativeModules.AudioMode;
  12. /**
  13. * Middleware that captures conference actions and sets the correct audio mode
  14. * based on the type of conference. Audio-only conferences don't use the speaker
  15. * by default, and video conferences do.
  16. *
  17. * @param {Store} store - The redux store.
  18. * @returns {Function}
  19. */
  20. MiddlewareRegistry.register(({ getState }) => next => action => {
  21. const result = next(action);
  22. if (AudioMode) {
  23. let mode;
  24. switch (action.type) {
  25. case APP_WILL_MOUNT:
  26. case CONFERENCE_FAILED:
  27. case CONFERENCE_LEFT:
  28. mode = AudioMode.DEFAULT;
  29. break;
  30. /*
  31. * NOTE: We moved the audio mode setting from CONFERENCE_WILL_JOIN to
  32. * CONFERENCE_JOINED because in case of a locked room, the app goes
  33. * through CONFERENCE_FAILED state and gets to CONFERENCE_JOINED only
  34. * after a correct password, so we want to make sure we have the correct
  35. * audio mode set up when we finally get to the conf, but also make sure
  36. * that the app is in the right audio mode if the user leaves the
  37. * conference after the password prompt appears.
  38. */
  39. case CONFERENCE_JOINED:
  40. case SET_AUDIO_ONLY: {
  41. const { audioOnly, conference }
  42. = getState()['features/base/conference'];
  43. conference
  44. && (mode = audioOnly
  45. ? AudioMode.AUDIO_CALL
  46. : AudioMode.VIDEO_CALL);
  47. break;
  48. }
  49. }
  50. if (typeof mode !== 'undefined') {
  51. AudioMode.setMode(mode)
  52. .catch(err =>
  53. console.error(
  54. `Failed to set audio mode ${String(mode)}: ${err}`));
  55. }
  56. }
  57. return result;
  58. });