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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // @flow
  2. import UIEvents from '../../../service/UI/UIEvents';
  3. import { getCurrentConference } from '../base/conference';
  4. import { getLocalParticipant } from '../base/participants';
  5. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  6. import { TOGGLE_SHARED_VIDEO } from './actionTypes';
  7. import { setDisableButton } from './actions.web';
  8. import { SHARED_VIDEO } from './constants';
  9. declare var APP: Object;
  10. /**
  11. * Middleware that captures actions related to video sharing and updates
  12. * components not hooked into redux.
  13. *
  14. * @param {Store} store - The redux store.
  15. * @returns {Function}
  16. */
  17. // eslint-disable-next-line no-unused-vars
  18. MiddlewareRegistry.register(store => next => action => {
  19. if (typeof APP === 'undefined') {
  20. return next(action);
  21. }
  22. switch (action.type) {
  23. case TOGGLE_SHARED_VIDEO:
  24. APP.UI.emitEvent(UIEvents.SHARED_VIDEO_CLICKED);
  25. break;
  26. }
  27. return next(action);
  28. });
  29. /**
  30. * Set up state change listener to disable or enable the share video button in
  31. * the toolbar menu.
  32. */
  33. StateListenerRegistry.register(
  34. state => getCurrentConference(state),
  35. (conference, store, previousConference) => {
  36. if (conference && conference !== previousConference) {
  37. conference.addCommandListener(SHARED_VIDEO,
  38. ({ attributes }) => {
  39. const { dispatch, getState } = store;
  40. const { from } = attributes;
  41. const localParticipantId = getLocalParticipant(getState()).id;
  42. const status = attributes.state;
  43. if (status === 'playing') {
  44. if (localParticipantId !== from) {
  45. dispatch(setDisableButton(true));
  46. }
  47. } else if (status === 'stop') {
  48. dispatch(setDisableButton(false));
  49. }
  50. }
  51. );
  52. }
  53. }
  54. );