選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

subscriber.ts 3.4KB

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