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.web.ts 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { AnyAction } from 'redux';
  2. import { IStore } from '../app/types';
  3. import { CONFERENCE_FAILED, CONFERENCE_JOINED } from '../base/conference/actionTypes';
  4. import { CONNECTION_FAILED } from '../base/connection/actionTypes';
  5. import { SET_AUDIO_MUTED, SET_VIDEO_MUTED } from '../base/media/actionTypes';
  6. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  7. import { updateSettings } from '../base/settings/actions';
  8. import {
  9. TRACK_ADDED,
  10. TRACK_NO_DATA_FROM_SOURCE
  11. } from '../base/tracks/actionTypes';
  12. import {
  13. setDeviceStatusOk,
  14. setDeviceStatusWarning,
  15. setJoiningInProgress
  16. } from './actions';
  17. import { isPrejoinPageVisible } from './functions.any';
  18. /**
  19. * The redux middleware for {@link PrejoinPage}.
  20. *
  21. * @param {Store} store - The redux store.
  22. * @returns {Function}
  23. */
  24. MiddlewareRegistry.register(store => next => action => {
  25. switch (action.type) {
  26. case SET_AUDIO_MUTED: {
  27. if (isPrejoinPageVisible(store.getState())) {
  28. store.dispatch(updateSettings({
  29. startWithAudioMuted: Boolean(action.muted)
  30. }));
  31. }
  32. break;
  33. }
  34. case SET_VIDEO_MUTED: {
  35. if (isPrejoinPageVisible(store.getState())) {
  36. store.dispatch(updateSettings({
  37. startWithVideoMuted: Boolean(action.muted)
  38. }));
  39. }
  40. break;
  41. }
  42. case TRACK_ADDED:
  43. case TRACK_NO_DATA_FROM_SOURCE: {
  44. const state = store.getState();
  45. if (isPrejoinPageVisible(state)) {
  46. const { track: { jitsiTrack: track } } = action;
  47. const { deviceStatusType, deviceStatusText } = state['features/prejoin'];
  48. if (!track.isAudioTrack()) {
  49. break;
  50. }
  51. if (track.isReceivingData()) {
  52. if (deviceStatusType === 'warning'
  53. && deviceStatusText === 'prejoin.audioDeviceProblem') {
  54. store.dispatch(setDeviceStatusOk('prejoin.lookGood'));
  55. }
  56. } else if (deviceStatusType === 'ok') {
  57. store.dispatch(setDeviceStatusWarning('prejoin.audioDeviceProblem'));
  58. }
  59. }
  60. break;
  61. }
  62. case CONFERENCE_FAILED:
  63. case CONNECTION_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 }: IStore, next: Function, action: AnyAction) {
  80. dispatch(setJoiningInProgress(false));
  81. return next(action);
  82. }