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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. 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 - Redux store.
  17. * @returns {Function}
  18. */
  19. MiddlewareRegistry.register(store => 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. case CONFERENCE_WILL_JOIN: {
  30. const { audioOnly } = store.getState()['features/base/conference'];
  31. mode = audioOnly ? AudioMode.AUDIO_CALL : AudioMode.VIDEO_CALL;
  32. break;
  33. }
  34. case SET_AUDIO_ONLY: {
  35. const { conference } = store.getState()['features/base/conference'];
  36. if (conference) {
  37. mode
  38. = action.audioOnly
  39. ? AudioMode.AUDIO_CALL
  40. : AudioMode.VIDEO_CALL;
  41. } else {
  42. mode = null;
  43. }
  44. break;
  45. }
  46. default:
  47. mode = null;
  48. break;
  49. }
  50. if (mode !== null) {
  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. });