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

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