2022-10-13 08:26:28 +00:00
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app/actionTypes';
|
|
|
|
import { CONFERENCE_JOINED } from '../base/conference/actionTypes';
|
2020-01-20 18:00:12 +00:00
|
|
|
import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
2022-10-13 08:26:28 +00:00
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
|
|
|
import { playSound, registerSound, unregisterSound } from '../base/sounds/actions';
|
|
|
|
import { hideNotification, showNotification } from '../notifications/actions';
|
|
|
|
import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
|
2020-01-20 18:00:12 +00:00
|
|
|
|
|
|
|
import { setNoisyAudioInputNotificationUid } from './actions';
|
|
|
|
import { NOISY_AUDIO_INPUT_SOUND_ID } from './constants';
|
|
|
|
import { NOISY_AUDIO_INPUT_SOUND_FILE } from './sounds';
|
|
|
|
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
store.dispatch(registerSound(NOISY_AUDIO_INPUT_SOUND_ID, NOISY_AUDIO_INPUT_SOUND_FILE));
|
|
|
|
break;
|
|
|
|
case APP_WILL_UNMOUNT:
|
|
|
|
store.dispatch(unregisterSound(NOISY_AUDIO_INPUT_SOUND_ID));
|
|
|
|
break;
|
|
|
|
case CONFERENCE_JOINED: {
|
|
|
|
const { dispatch, getState } = store;
|
|
|
|
const { conference } = action;
|
|
|
|
|
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.TRACK_MUTE_CHANGED,
|
2022-10-13 08:26:28 +00:00
|
|
|
(track: any) => {
|
2020-01-20 18:00:12 +00:00
|
|
|
const { noisyAudioInputNotificationUid } = getState()['features/noise-detection'];
|
|
|
|
|
|
|
|
// Hide the notification in case the user mutes the microphone
|
|
|
|
if (noisyAudioInputNotificationUid && track.isAudioTrack() && track.isLocal() && track.isMuted()) {
|
|
|
|
dispatch(hideNotification(noisyAudioInputNotificationUid));
|
|
|
|
dispatch(setNoisyAudioInputNotificationUid());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
conference.on(
|
2021-01-11 10:52:52 +00:00
|
|
|
JitsiConferenceEvents.NOISY_MIC, async () => {
|
|
|
|
const notification = await dispatch(showNotification({
|
2020-01-20 18:00:12 +00:00
|
|
|
titleKey: 'toolbar.noisyAudioInputTitle',
|
|
|
|
descriptionKey: 'toolbar.noisyAudioInputDesc'
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
|
2020-01-20 18:00:12 +00:00
|
|
|
|
|
|
|
dispatch(playSound(NOISY_AUDIO_INPUT_SOUND_ID));
|
|
|
|
|
2021-01-11 10:52:52 +00:00
|
|
|
if (notification) {
|
|
|
|
// we store the last notification id so we can hide it if the mic is muted
|
|
|
|
dispatch(setNoisyAudioInputNotificationUid(notification.uid));
|
|
|
|
}
|
2020-01-20 18:00:12 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|