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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_WILL_JOIN
  8. } from '../base/conference';
  9. import { MiddlewareRegistry } from '../base/redux';
  10. /**
  11. * Middleware that captures conference actions and sets the correct audio mode
  12. * based on the type of conference. Audio-only conferences don't use the speaker
  13. * by default, and video conferences do.
  14. *
  15. * @param {Store} store - Redux store.
  16. * @returns {Function}
  17. */
  18. MiddlewareRegistry.register(store => next => action => {
  19. const AudioMode = NativeModules.AudioMode;
  20. // The react-native module AudioMode is implemented on iOS at the time of
  21. // this writing.
  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. case CONFERENCE_WILL_JOIN: {
  31. const conference = store.getState()['features/base/conference'];
  32. mode
  33. = conference.audioOnly
  34. ? AudioMode.AUDIO_CALL
  35. : AudioMode.VIDEO_CALL;
  36. break;
  37. }
  38. default:
  39. mode = null;
  40. break;
  41. }
  42. if (mode !== null) {
  43. AudioMode.setMode(mode)
  44. .catch(err =>
  45. console.error(
  46. `Failed to set audio mode ${String(mode)}: `
  47. + `${err}`));
  48. }
  49. }
  50. return next(action);
  51. });