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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // @flow
  2. import { CONFERENCE_FAILED, CONFERENCE_JOINED } from '../base/conference';
  3. import { SET_AUDIO_MUTED, SET_VIDEO_MUTED } from '../base/media';
  4. import { MiddlewareRegistry } from '../base/redux';
  5. import { updateSettings } from '../base/settings';
  6. import {
  7. TRACK_ADDED,
  8. TRACK_NO_DATA_FROM_SOURCE
  9. } from '../base/tracks';
  10. import {
  11. setDeviceStatusOk,
  12. setDeviceStatusWarning,
  13. setJoiningInProgress,
  14. setPrejoinPageVisibility
  15. } from './actions';
  16. import { PREJOIN_SCREEN_STATES } from './constants';
  17. import { isPrejoinPageVisible } from './functions';
  18. declare var APP: Object;
  19. /**
  20. * The redux middleware for {@link PrejoinPage}.
  21. *
  22. * @param {Store} store - The redux store.
  23. * @returns {Function}
  24. */
  25. MiddlewareRegistry.register(store => next => async action => {
  26. switch (action.type) {
  27. case SET_AUDIO_MUTED: {
  28. if (isPrejoinPageVisible(store.getState())) {
  29. store.dispatch(updateSettings({
  30. startWithAudioMuted: Boolean(action.muted)
  31. }));
  32. }
  33. break;
  34. }
  35. case SET_VIDEO_MUTED: {
  36. if (isPrejoinPageVisible(store.getState())) {
  37. store.dispatch(updateSettings({
  38. startWithVideoMuted: Boolean(action.muted)
  39. }));
  40. }
  41. break;
  42. }
  43. case TRACK_ADDED:
  44. case TRACK_NO_DATA_FROM_SOURCE: {
  45. const state = store.getState();
  46. if (isPrejoinPageVisible(state)) {
  47. const { track: { jitsiTrack: track } } = action;
  48. const { deviceStatusType, deviceStatusText } = state['features/prejoin'];
  49. if (!track.isAudioTrack()) {
  50. break;
  51. }
  52. if (track.isReceivingData()) {
  53. if (deviceStatusType === 'warning'
  54. && deviceStatusText === 'prejoin.audioDeviceProblem') {
  55. store.dispatch(setDeviceStatusOk('prejoin.lookGood'));
  56. }
  57. } else if (deviceStatusType === 'ok') {
  58. store.dispatch(setDeviceStatusWarning('prejoin.audioDeviceProblem'));
  59. }
  60. }
  61. break;
  62. }
  63. case CONFERENCE_FAILED:
  64. store.dispatch(setJoiningInProgress(false));
  65. break;
  66. case CONFERENCE_JOINED:
  67. return _conferenceJoined(store, next, action);
  68. }
  69. return next(action);
  70. });
  71. /**
  72. * Handles cleanup of prejoin state when a conference is joined.
  73. *
  74. * @param {Object} store - The Redux store.
  75. * @param {Function} next - The Redux next function.
  76. * @param {Object} action - The Redux action.
  77. * @returns {Object}
  78. */
  79. function _conferenceJoined({ dispatch }, next, action) {
  80. dispatch(setPrejoinPageVisibility(PREJOIN_SCREEN_STATES.HIDDEN));
  81. dispatch(setJoiningInProgress(false));
  82. return next(action);
  83. }