Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

middleware.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. 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 { audioOnly, conference }
  48. = getState()['features/base/conference'];
  49. conference
  50. && (mode = audioOnly
  51. ? AudioMode.AUDIO_CALL
  52. : AudioMode.VIDEO_CALL);
  53. break;
  54. }
  55. }
  56. if (typeof mode !== 'undefined') {
  57. AudioMode.setMode(mode)
  58. .catch(err =>
  59. logger.error(
  60. `Failed to set audio mode ${String(mode)}: ${err}`));
  61. }
  62. }
  63. return result;
  64. });