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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // @flow
  2. import { MiddlewareRegistry } from '../base/redux';
  3. import { toggleRequestingSubtitles } from '../subtitles';
  4. import {
  5. HIDDEN_PARTICIPANT_JOINED,
  6. HIDDEN_PARTICIPANT_LEFT,
  7. PARTICIPANT_UPDATED
  8. } from './../base/participants';
  9. import {
  10. _TRANSCRIBER_JOINED,
  11. _TRANSCRIBER_LEFT
  12. } from './actionTypes';
  13. import {
  14. hidePendingTranscribingNotification,
  15. potentialTranscriberJoined,
  16. showStoppedTranscribingNotification,
  17. transcriberJoined,
  18. transcriberLeft
  19. } from './actions';
  20. const TRANSCRIBER_DISPLAY_NAME = 'Transcriber';
  21. /**
  22. * Implements the middleware of the feature transcribing.
  23. *
  24. * @param {Store} store - The redux store.
  25. * @returns {Function}
  26. */
  27. // eslint-disable-next-line no-unused-vars
  28. MiddlewareRegistry.register(store => next => action => {
  29. const {
  30. transcriberJID,
  31. potentialTranscriberJIDs
  32. } = store.getState()['features/transcribing'];
  33. switch (action.type) {
  34. case _TRANSCRIBER_LEFT: {
  35. store.dispatch(showStoppedTranscribingNotification());
  36. const state = store.getState();
  37. const { transcription } = state['features/base/config'];
  38. const { _requestingSubtitles } = state['features/subtitles'];
  39. if (_requestingSubtitles && !transcription?.disableStartForAll) {
  40. store.dispatch(toggleRequestingSubtitles());
  41. }
  42. break;
  43. }
  44. case HIDDEN_PARTICIPANT_JOINED:
  45. if (action.displayName
  46. && action.displayName === TRANSCRIBER_DISPLAY_NAME) {
  47. store.dispatch(transcriberJoined(action.id));
  48. } else {
  49. store.dispatch(potentialTranscriberJoined(action.id));
  50. }
  51. break;
  52. case HIDDEN_PARTICIPANT_LEFT:
  53. if (action.id === transcriberJID) {
  54. store.dispatch(transcriberLeft(action.id));
  55. }
  56. break;
  57. case PARTICIPANT_UPDATED: {
  58. const { participant } = action;
  59. if (potentialTranscriberJIDs.includes(participant.id)
  60. && participant.name === TRANSCRIBER_DISPLAY_NAME) {
  61. store.dispatch(transcriberJoined(participant.id));
  62. store.dispatch(hidePendingTranscribingNotification());
  63. }
  64. break;
  65. }
  66. case _TRANSCRIBER_JOINED: {
  67. const state = store.getState();
  68. const { transcription } = state['features/base/config'];
  69. const { _requestingSubtitles } = state['features/subtitles'];
  70. if (!_requestingSubtitles && !transcription?.disableStartForAll) {
  71. store.dispatch(toggleRequestingSubtitles());
  72. }
  73. break;
  74. }
  75. }
  76. return next(action);
  77. });