您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.ts 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {
  2. HIDDEN_PARTICIPANT_JOINED,
  3. HIDDEN_PARTICIPANT_LEFT,
  4. PARTICIPANT_UPDATED
  5. } from '../base/participants/actionTypes';
  6. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  7. import {
  8. potentialTranscriberJoined,
  9. transcriberJoined,
  10. transcriberLeft
  11. } from './actions';
  12. import './subscriber';
  13. const TRANSCRIBER_DISPLAY_NAME = 'Transcriber';
  14. /**
  15. * Implements the middleware of the feature transcribing.
  16. *
  17. * @param {Store} store - The redux store.
  18. * @returns {Function}
  19. */
  20. // eslint-disable-next-line no-unused-vars
  21. MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
  22. const {
  23. transcriberJID,
  24. potentialTranscriberJIDs
  25. } = getState()['features/transcribing'];
  26. switch (action.type) {
  27. case HIDDEN_PARTICIPANT_JOINED:
  28. if (action.displayName === TRANSCRIBER_DISPLAY_NAME) {
  29. dispatch(transcriberJoined(action.id));
  30. } else {
  31. dispatch(potentialTranscriberJoined(action.id));
  32. }
  33. break;
  34. case HIDDEN_PARTICIPANT_LEFT:
  35. if (action.id === transcriberJID) {
  36. dispatch(transcriberLeft(action.id));
  37. }
  38. break;
  39. case PARTICIPANT_UPDATED: {
  40. const { participant } = action;
  41. if (potentialTranscriberJIDs.includes(participant.id) && participant.name === TRANSCRIBER_DISPLAY_NAME) {
  42. dispatch(transcriberJoined(participant.id));
  43. }
  44. break;
  45. }
  46. }
  47. return next(action);
  48. });