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

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