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.

subscriber.ts 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { batch } from 'react-redux';
  2. import { IStore } from '../app/types';
  3. import { JitsiRecordingConstants } from '../base/lib-jitsi-meet';
  4. import StateListenerRegistry from '../base/redux/StateListenerRegistry';
  5. import { playSound } from '../base/sounds/actions';
  6. import { showNotification } from '../notifications/actions';
  7. import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
  8. import { RECORDING_OFF_SOUND_ID, RECORDING_ON_SOUND_ID } from '../recording/constants';
  9. import { isLiveStreamingRunning, isRecordingRunning } from '../recording/functions';
  10. import { isRecorderTranscriptionsRunning } from './functions';
  11. /**
  12. * Listens for transcriber status change.
  13. */
  14. StateListenerRegistry.register(
  15. /* selector */ isRecorderTranscriptionsRunning,
  16. /* listener */ (isRecorderTranscriptionsRunningValue, { getState, dispatch }) => {
  17. if (isRecorderTranscriptionsRunningValue) {
  18. notifyTranscribingStatusChanged(getState, true);
  19. maybeEmitRecordingNotification(dispatch, getState, true);
  20. } else {
  21. notifyTranscribingStatusChanged(getState, false);
  22. maybeEmitRecordingNotification(dispatch, getState, false);
  23. }
  24. }
  25. );
  26. /**
  27. * Emit a recording started / stopped notification if the transcription started / stopped. Only
  28. * if there is no recording in progress.
  29. *
  30. * @param {Dispatch} dispatch - The Redux dispatch function.
  31. * @param {Function} getState - The Redux state.
  32. * @param {boolean} on - Whether the transcription is on or not.
  33. *
  34. * @returns {void}
  35. */
  36. function maybeEmitRecordingNotification(dispatch: IStore['dispatch'], getState: IStore['getState'], on: boolean) {
  37. const state = getState();
  38. const { sessionDatas } = state['features/recording'];
  39. const { mode: modeConstants, status: statusConstants } = JitsiRecordingConstants;
  40. if (sessionDatas.some(sd => sd.mode === modeConstants.FILE && sd.status === statusConstants.ON)) {
  41. // If a recording is still ongoing, don't send any notification.
  42. return;
  43. }
  44. batch(() => {
  45. dispatch(showNotification({
  46. descriptionKey: on ? 'recording.on' : 'recording.off',
  47. titleKey: 'dialog.recording'
  48. }, NOTIFICATION_TIMEOUT_TYPE.SHORT));
  49. dispatch(playSound(on ? RECORDING_ON_SOUND_ID : RECORDING_OFF_SOUND_ID));
  50. });
  51. }
  52. /**
  53. * Notify external application (if API is enabled) that transcribing has started or stopped.
  54. *
  55. * @param {Function} getState - The Redux state.
  56. * @param {boolean} on - True if transcribing is on, false otherwise.
  57. * @returns {void}
  58. */
  59. function notifyTranscribingStatusChanged(getState: IStore['getState'], on: boolean) {
  60. if (typeof APP !== 'undefined') {
  61. const state = getState();
  62. const isRecording = isRecordingRunning(state);
  63. const isStreaming = isLiveStreamingRunning(state);
  64. const mode = isRecording ? JitsiRecordingConstants.mode.FILE : JitsiRecordingConstants.mode.STREAM;
  65. APP.API.notifyRecordingStatusChanged(isRecording || isStreaming, mode, undefined, on);
  66. APP.API.notifyTranscribingStatusChanged(on);
  67. }
  68. }