2020-02-05 18:10:57 +00:00
|
|
|
import React from 'react';
|
2022-10-13 08:26:28 +00:00
|
|
|
import { AnyAction } from 'redux';
|
2020-02-05 18:10:57 +00:00
|
|
|
|
2022-10-13 08:26:28 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app/actionTypes';
|
|
|
|
import { CONFERENCE_JOINED } from '../base/conference/actionTypes';
|
|
|
|
import { setAudioInputDevice } from '../base/devices/actions';
|
|
|
|
import { formatDeviceLabel } from '../base/devices/functions';
|
2019-11-22 14:02:59 +00:00
|
|
|
import JitsiMeetJS, { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
2022-10-13 08:26:28 +00:00
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
|
|
|
import { updateSettings } from '../base/settings/actions';
|
|
|
|
import { playSound, registerSound, unregisterSound } from '../base/sounds/actions';
|
|
|
|
import { hideNotification, showNotification } from '../notifications/actions';
|
|
|
|
import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
|
2019-10-03 08:15:49 +00:00
|
|
|
|
2019-12-05 12:11:26 +00:00
|
|
|
import { setNoAudioSignalNotificationUid } from './actions';
|
2022-10-13 08:26:28 +00:00
|
|
|
// eslint-disable-next-line lines-around-comment
|
|
|
|
// @ts-ignore
|
2020-02-05 18:10:57 +00:00
|
|
|
import DialInLink from './components/DialInLink';
|
2019-12-05 12:11:26 +00:00
|
|
|
import { NO_AUDIO_SIGNAL_SOUND_ID } from './constants';
|
|
|
|
import { NO_AUDIO_SIGNAL_SOUND_FILE } from './sounds';
|
|
|
|
|
2019-10-03 08:15:49 +00:00
|
|
|
MiddlewareRegistry.register(store => next => async action => {
|
|
|
|
const result = next(action);
|
2019-12-05 12:11:26 +00:00
|
|
|
const { dispatch } = store;
|
2019-10-03 08:15:49 +00:00
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
dispatch(registerSound(NO_AUDIO_SIGNAL_SOUND_ID, NO_AUDIO_SIGNAL_SOUND_FILE));
|
|
|
|
break;
|
|
|
|
case APP_WILL_UNMOUNT:
|
|
|
|
dispatch(unregisterSound(NO_AUDIO_SIGNAL_SOUND_ID));
|
|
|
|
break;
|
2019-12-05 12:11:26 +00:00
|
|
|
case CONFERENCE_JOINED:
|
|
|
|
_handleNoAudioSignalNotification(store, action);
|
2019-10-03 08:15:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|
2019-12-05 12:11:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the logic of displaying the no audio input detected notification as well as finding a valid device on the
|
|
|
|
* system.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified action is being dispatched.
|
|
|
|
* @param {Action} action - The redux action {@code CONFERENCE_JOINED} which is being dispatched in the specified redux
|
|
|
|
* store.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-10-13 08:26:28 +00:00
|
|
|
async function _handleNoAudioSignalNotification({ dispatch, getState }: IStore, action: AnyAction) {
|
2019-12-05 12:11:26 +00:00
|
|
|
|
|
|
|
const { conference } = action;
|
|
|
|
|
2022-10-13 08:26:28 +00:00
|
|
|
conference.on(JitsiConferenceEvents.AUDIO_INPUT_STATE_CHANGE, (hasAudioInput: boolean) => {
|
2019-12-05 12:11:26 +00:00
|
|
|
const { noAudioSignalNotificationUid } = getState()['features/no-audio-signal'];
|
|
|
|
|
|
|
|
// In case the notification is displayed but the conference detected audio input signal we hide it.
|
|
|
|
if (noAudioSignalNotificationUid && hasAudioInput) {
|
|
|
|
dispatch(hideNotification(noAudioSignalNotificationUid));
|
|
|
|
dispatch(setNoAudioSignalNotificationUid());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
conference.on(JitsiConferenceEvents.NO_AUDIO_INPUT, async () => {
|
|
|
|
const { noSrcDataNotificationUid } = getState()['features/base/no-src-data'];
|
|
|
|
|
|
|
|
// In case the 'no data detected from source' notification was already shown, we prevent the
|
|
|
|
// no audio signal notification as it's redundant i.e. it's clear that the users microphone is
|
|
|
|
// muted from system settings.
|
|
|
|
if (noSrcDataNotificationUid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const activeDevice = await JitsiMeetJS.getActiveAudioDevice();
|
|
|
|
|
|
|
|
// In case there is a previous notification displayed just hide it.
|
|
|
|
const { noAudioSignalNotificationUid } = getState()['features/no-audio-signal'];
|
|
|
|
|
|
|
|
if (noAudioSignalNotificationUid) {
|
|
|
|
dispatch(hideNotification(noAudioSignalNotificationUid));
|
|
|
|
dispatch(setNoAudioSignalNotificationUid());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let descriptionKey = 'toolbar.noAudioSignalDesc';
|
|
|
|
let customActionNameKey;
|
|
|
|
let customActionHandler;
|
|
|
|
|
|
|
|
// In case the detector picked up a device show a notification with a device suggestion
|
|
|
|
if (activeDevice.deviceLabel !== '') {
|
|
|
|
descriptionKey = 'toolbar.noAudioSignalDescSuggestion';
|
|
|
|
|
|
|
|
// Preferably the label should be passed as an argument paired with a i18next string, however
|
|
|
|
// at the point of the implementation the showNotification function only supports doing that for
|
|
|
|
// the description.
|
|
|
|
// TODO Add support for arguments to showNotification title and customAction strings.
|
2021-11-10 11:19:40 +00:00
|
|
|
customActionNameKey = [ `Switch to ${formatDeviceLabel(activeDevice.deviceLabel)}` ];
|
|
|
|
customActionHandler = [ () => {
|
2019-12-05 12:11:26 +00:00
|
|
|
// Select device callback
|
|
|
|
dispatch(
|
|
|
|
updateSettings({
|
|
|
|
userSelectedMicDeviceId: activeDevice.deviceId,
|
|
|
|
userSelectedMicDeviceLabel: activeDevice.deviceLabel
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
dispatch(setAudioInputDevice(activeDevice.deviceId));
|
2021-11-10 11:19:40 +00:00
|
|
|
} ];
|
2019-12-05 12:11:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 10:52:52 +00:00
|
|
|
const notification = await dispatch(showNotification({
|
2019-12-05 12:11:26 +00:00
|
|
|
titleKey: 'toolbar.noAudioSignalTitle',
|
2020-02-05 18:10:57 +00:00
|
|
|
description: <DialInLink />,
|
2019-12-05 12:11:26 +00:00
|
|
|
descriptionKey,
|
|
|
|
customActionNameKey,
|
|
|
|
customActionHandler
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.LONG));
|
2019-12-05 12:11:26 +00:00
|
|
|
|
|
|
|
dispatch(playSound(NO_AUDIO_SIGNAL_SOUND_ID));
|
|
|
|
|
2021-01-11 10:52:52 +00:00
|
|
|
if (notification) {
|
|
|
|
// Store the current notification uid so we can check for this state and hide it in case
|
|
|
|
// a new track was added, thus changing the context of the notification
|
|
|
|
dispatch(setNoAudioSignalNotificationUid(notification.uid));
|
|
|
|
}
|
2019-12-05 12:11:26 +00:00
|
|
|
});
|
|
|
|
}
|