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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // @flow
  2. import { MiddlewareRegistry } from '../base/redux';
  3. import {
  4. _TRANSCRIBER_LEFT,
  5. DIAL_TRANSCRIBER,
  6. STOP_TRANSCRIBING
  7. } from './actionTypes';
  8. import {
  9. dialError,
  10. hidePendingTranscribingNotification,
  11. potentialTranscriberJoined,
  12. showPendingTranscribingNotification,
  13. showStoppedTranscribingNotification,
  14. showTranscribingError,
  15. transcriberJoined,
  16. transcriberLeft
  17. } from './actions';
  18. import {
  19. HIDDEN_PARTICIPANT_JOINED,
  20. HIDDEN_PARTICIPANT_LEFT,
  21. PARTICIPANT_UPDATED
  22. } from './../base/participants';
  23. declare var APP: Object;
  24. const TRANSCRIBER_DIAL_COMMAND = 'jitsi_meet_transcribe';
  25. const TRANSCRIBER_DISPLAY_NAME = 'Transcriber';
  26. /**
  27. * Implements the middleware of the feature transcribing.
  28. *
  29. * @param {Store} store - The redux store.
  30. * @returns {Function}
  31. */
  32. // eslint-disable-next-line no-unused-vars
  33. MiddlewareRegistry.register(store => next => action => {
  34. const {
  35. isDialing,
  36. isTranscribing,
  37. transcriberJID,
  38. potentialTranscriberJIDs
  39. } = store.getState()['features/transcribing'];
  40. const { conference } = store.getState()['features/base/conference'];
  41. switch (action.type) {
  42. case DIAL_TRANSCRIBER:
  43. if (!(isDialing || isTranscribing)) {
  44. store.dispatch(showPendingTranscribingNotification());
  45. conference.room.dial(TRANSCRIBER_DIAL_COMMAND).catch(
  46. () => {
  47. store.dispatch(dialError());
  48. store.dispatch(hidePendingTranscribingNotification());
  49. store.dispatch(showTranscribingError());
  50. }
  51. );
  52. }
  53. break;
  54. case STOP_TRANSCRIBING:
  55. if (isTranscribing) {
  56. const participant = conference.getParticipantById(transcriberJID);
  57. conference.room.kick(participant.getJid());
  58. }
  59. break;
  60. case _TRANSCRIBER_LEFT:
  61. store.dispatch(showStoppedTranscribingNotification());
  62. break;
  63. case HIDDEN_PARTICIPANT_JOINED:
  64. if (action.displayName
  65. && action.displayName === TRANSCRIBER_DISPLAY_NAME) {
  66. store.dispatch(transcriberJoined(action.id));
  67. } else {
  68. store.dispatch(potentialTranscriberJoined(action.id));
  69. }
  70. break;
  71. case HIDDEN_PARTICIPANT_LEFT:
  72. if (action.id === transcriberJID) {
  73. store.dispatch(transcriberLeft(action.id));
  74. }
  75. break;
  76. case PARTICIPANT_UPDATED: {
  77. const { participant } = action;
  78. if (potentialTranscriberJIDs.includes(participant.id)
  79. && participant.name === TRANSCRIBER_DISPLAY_NAME) {
  80. store.dispatch(transcriberJoined(participant.id));
  81. store.dispatch(hidePendingTranscribingNotification());
  82. }
  83. break;
  84. }
  85. }
  86. return next(action);
  87. });