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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_JOINED,
  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. /*
  30. * NOTE: We moved the audio mode setting from CONFERENCE_WILL_JOIN to
  31. * CONFERENCE_JOINED because in case of a locked room, the app goes
  32. * through CONFERENCE_FAILED state and gets to CONFERENCE_JOINED only
  33. * after a correct password, so we want to make sure we have the correct
  34. * audio mode set up when we finally get to the conf, but also make sure
  35. * that the app is in the right audio mode if the user leaves the
  36. * conference after the password prompt appears.
  37. */
  38. case CONFERENCE_JOINED:
  39. case SET_AUDIO_ONLY: {
  40. if (getState()['features/base/conference'].conference
  41. || action.conference) {
  42. mode
  43. = action.audioOnly
  44. ? AudioMode.AUDIO_CALL
  45. : AudioMode.VIDEO_CALL;
  46. }
  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 next(action);
  58. });