This commit is contained in:
11
react/features/noise-detection/actionTypes.ts
Normal file
11
react/features/noise-detection/actionTypes.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* The type of Redux action which sets the pending notification UID
|
||||
* to use it when hiding the notification is necessary, or unset it when
|
||||
* undefined (or no param) is passed.
|
||||
*
|
||||
* {
|
||||
* type: SET_NOISY_AUDIO_INPUT_NOTIFICATION_UID
|
||||
* uid: ?number
|
||||
* }
|
||||
*/
|
||||
export const SET_NOISY_AUDIO_INPUT_NOTIFICATION_UID = 'SET_NOISY_AUDIO_INPUT_NOTIFICATION_UID';
|
||||
19
react/features/noise-detection/actions.ts
Normal file
19
react/features/noise-detection/actions.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { SET_NOISY_AUDIO_INPUT_NOTIFICATION_UID } from './actionTypes';
|
||||
|
||||
/**
|
||||
* Sets UID of the the pending notification to use it when hiding
|
||||
* the notification is necessary, or unset it when undefined (or no param) is
|
||||
* passed.
|
||||
*
|
||||
* @param {?number} uid - The UID of the notification.
|
||||
* @returns {{
|
||||
* type: SET_NOISY_AUDIO_INPUT_NOTIFICATION_UID,
|
||||
* uid: number
|
||||
* }}
|
||||
*/
|
||||
export function setNoisyAudioInputNotificationUid(uid?: string) {
|
||||
return {
|
||||
type: SET_NOISY_AUDIO_INPUT_NOTIFICATION_UID,
|
||||
uid
|
||||
};
|
||||
}
|
||||
6
react/features/noise-detection/constants.ts
Normal file
6
react/features/noise-detection/constants.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* The identifier of the sound to be played when we display a you are noisy notification.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
export const NOISY_AUDIO_INPUT_SOUND_ID = 'NOISY_AUDIO_INPUT_SOUND';
|
||||
57
react/features/noise-detection/middleware.ts
Normal file
57
react/features/noise-detection/middleware.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app/actionTypes';
|
||||
import { CONFERENCE_JOINED } from '../base/conference/actionTypes';
|
||||
import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
||||
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';
|
||||
|
||||
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,
|
||||
(track: any) => {
|
||||
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(
|
||||
JitsiConferenceEvents.NOISY_MIC, () => {
|
||||
const notification = dispatch(showNotification({
|
||||
titleKey: 'toolbar.noisyAudioInputTitle',
|
||||
descriptionKey: 'toolbar.noisyAudioInputDesc'
|
||||
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
|
||||
|
||||
dispatch(playSound(NOISY_AUDIO_INPUT_SOUND_ID));
|
||||
|
||||
if (notification) {
|
||||
// we store the last notification id so we can hide it if the mic is muted
|
||||
dispatch(setNoisyAudioInputNotificationUid(notification.uid));
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
21
react/features/noise-detection/reducer.ts
Normal file
21
react/features/noise-detection/reducer.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
||||
import { set } from '../base/redux/functions';
|
||||
|
||||
import { SET_NOISY_AUDIO_INPUT_NOTIFICATION_UID } from './actionTypes';
|
||||
|
||||
export interface INoiseDetectionState {
|
||||
noisyAudioInputNotificationUid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces the redux actions of noise detection feature.
|
||||
*/
|
||||
ReducerRegistry.register<INoiseDetectionState>('features/noise-detection',
|
||||
(state = {}, action): INoiseDetectionState => {
|
||||
switch (action.type) {
|
||||
case SET_NOISY_AUDIO_INPUT_NOTIFICATION_UID:
|
||||
return set(state, 'noisyAudioInputNotificationUid', action.uid);
|
||||
}
|
||||
|
||||
return state;
|
||||
});
|
||||
6
react/features/noise-detection/sounds.ts
Normal file
6
react/features/noise-detection/sounds.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* The file used for the noisy audio input notification.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
export const NOISY_AUDIO_INPUT_SOUND_FILE = 'noisyAudioInput.mp3';
|
||||
Reference in New Issue
Block a user