2022-10-28 06:41:12 +00:00
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app/actionTypes';
|
|
|
|
import { CONFERENCE_JOINED } from '../base/conference/actionTypes';
|
2019-07-23 20:56:05 +00:00
|
|
|
import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
2022-10-28 06:41:12 +00:00
|
|
|
import { setAudioMuted } from '../base/media/actions';
|
|
|
|
import { MEDIA_TYPE } from '../base/media/constants';
|
|
|
|
import { raiseHand } from '../base/participants/actions';
|
|
|
|
import { getLocalParticipant } from '../base/participants/functions';
|
|
|
|
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';
|
2021-09-10 11:05:16 +00:00
|
|
|
import { isForceMuted } from '../participants-pane/functions';
|
2021-11-30 20:08:25 +00:00
|
|
|
import { isAudioMuteButtonDisabled } from '../toolbox/functions.any';
|
2019-07-23 20:56:05 +00:00
|
|
|
|
|
|
|
import { setCurrentNotificationUid } from './actions';
|
|
|
|
import { TALK_WHILE_MUTED_SOUND_ID } from './constants';
|
|
|
|
import { TALK_WHILE_MUTED_SOUND_FILE } from './sounds';
|
|
|
|
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
const result = next(action);
|
|
|
|
const { dispatch, getState } = store;
|
|
|
|
const { conference } = action;
|
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
dispatch(registerSound(TALK_WHILE_MUTED_SOUND_ID, TALK_WHILE_MUTED_SOUND_FILE));
|
|
|
|
break;
|
|
|
|
case APP_WILL_UNMOUNT:
|
|
|
|
dispatch(unregisterSound(TALK_WHILE_MUTED_SOUND_ID));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFERENCE_JOINED: {
|
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.TRACK_MUTE_CHANGED,
|
2022-10-28 06:41:12 +00:00
|
|
|
(track: any) => {
|
2019-07-23 20:56:05 +00:00
|
|
|
const { currentNotificationUid } = getState()['features/talk-while-muted'];
|
|
|
|
|
|
|
|
if (currentNotificationUid && track.isAudioTrack() && track.isLocal() && !track.isMuted()) {
|
|
|
|
dispatch(hideNotification(currentNotificationUid));
|
|
|
|
dispatch(setCurrentNotificationUid());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
conference.on(
|
2021-01-11 10:52:52 +00:00
|
|
|
JitsiConferenceEvents.TALK_WHILE_MUTED, async () => {
|
2021-09-10 11:05:16 +00:00
|
|
|
const state = getState();
|
|
|
|
const local = getLocalParticipant(state);
|
2019-07-23 20:56:05 +00:00
|
|
|
|
2021-11-30 20:08:25 +00:00
|
|
|
// Display the talk while muted notification only when the audio button is not disabled.
|
|
|
|
if (!isAudioMuteButtonDisabled(state)) {
|
|
|
|
const forceMuted = isForceMuted(local, MEDIA_TYPE.AUDIO, state);
|
|
|
|
const notification = await dispatch(showNotification({
|
|
|
|
titleKey: 'toolbar.talkWhileMutedPopup',
|
2021-11-10 11:19:40 +00:00
|
|
|
customActionNameKey: [ forceMuted ? 'notify.raiseHandAction' : 'notify.unmute' ],
|
|
|
|
customActionHandler: [ () => dispatch(forceMuted ? raiseHand(true) : setAudioMuted(false)) ]
|
2021-11-30 20:08:25 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.LONG));
|
2021-07-20 11:56:57 +00:00
|
|
|
|
2021-11-30 20:08:25 +00:00
|
|
|
const { soundsTalkWhileMuted } = getState()['features/base/settings'];
|
2021-07-20 11:56:57 +00:00
|
|
|
|
2021-11-30 20:08:25 +00:00
|
|
|
if (soundsTalkWhileMuted) {
|
|
|
|
dispatch(playSound(TALK_WHILE_MUTED_SOUND_ID));
|
|
|
|
}
|
2019-07-23 20:56:05 +00:00
|
|
|
|
2021-11-30 20:08:25 +00:00
|
|
|
if (notification) {
|
|
|
|
// we store the last start muted notification id that we showed,
|
|
|
|
// so we can hide it when unmuted mic is detected
|
|
|
|
dispatch(setCurrentNotificationUid(notification.uid));
|
|
|
|
}
|
2021-01-11 10:52:52 +00:00
|
|
|
}
|
2019-07-23 20:56:05 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|