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

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