|
|
@@ -1,7 +1,5 @@
|
|
1
|
1
|
// @flow
|
|
2
|
|
-import { setNoAudioSignalNotificationUid } from './actions';
|
|
3
|
|
-import { NO_AUDIO_SIGNAL_SOUND_ID } from './constants';
|
|
4
|
|
-import { NO_AUDIO_SIGNAL_SOUND_FILE } from './sounds';
|
|
|
2
|
+
|
|
5
|
3
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
|
|
6
|
4
|
import { CONFERENCE_JOINED } from '../base/conference';
|
|
7
|
5
|
import {
|
|
|
@@ -14,11 +12,13 @@ import { updateSettings } from '../base/settings';
|
|
14
|
12
|
import { playSound, registerSound, unregisterSound } from '../base/sounds';
|
|
15
|
13
|
import { hideNotification, showNotification } from '../notifications';
|
|
16
|
14
|
|
|
|
15
|
+import { setNoAudioSignalNotificationUid } from './actions';
|
|
|
16
|
+import { NO_AUDIO_SIGNAL_SOUND_ID } from './constants';
|
|
|
17
|
+import { NO_AUDIO_SIGNAL_SOUND_FILE } from './sounds';
|
|
|
18
|
+
|
|
17
|
19
|
MiddlewareRegistry.register(store => next => async action => {
|
|
18
|
20
|
const result = next(action);
|
|
19
|
|
- const { dispatch, getState } = store;
|
|
20
|
|
- const { conference } = action;
|
|
21
|
|
- let confAudioInputState;
|
|
|
21
|
+ const { dispatch } = store;
|
|
22
|
22
|
|
|
23
|
23
|
switch (action.type) {
|
|
24
|
24
|
case APP_WILL_MOUNT:
|
|
|
@@ -27,93 +27,109 @@ MiddlewareRegistry.register(store => next => async action => {
|
|
27
|
27
|
case APP_WILL_UNMOUNT:
|
|
28
|
28
|
dispatch(unregisterSound(NO_AUDIO_SIGNAL_SOUND_ID));
|
|
29
|
29
|
break;
|
|
30
|
|
-
|
|
31
|
|
- case CONFERENCE_JOINED: {
|
|
32
|
|
- conference.on(JitsiConferenceEvents.AUDIO_INPUT_STATE_CHANGE, hasAudioInput => {
|
|
33
|
|
- const { noAudioSignalNotificationUid } = getState()['features/no-audio-signal'];
|
|
34
|
|
-
|
|
35
|
|
- confAudioInputState = hasAudioInput;
|
|
36
|
|
-
|
|
37
|
|
- // In case the notification is displayed but the conference detected audio input signal we hide it.
|
|
38
|
|
- if (noAudioSignalNotificationUid && hasAudioInput) {
|
|
39
|
|
- dispatch(hideNotification(noAudioSignalNotificationUid));
|
|
40
|
|
- dispatch(setNoAudioSignalNotificationUid());
|
|
41
|
|
- }
|
|
42
|
|
- });
|
|
43
|
|
- conference.on(JitsiConferenceEvents.NO_AUDIO_INPUT, async () => {
|
|
44
|
|
- const { noSrcDataNotificationUid } = getState()['features/base/no-src-data'];
|
|
45
|
|
-
|
|
46
|
|
- // In case the 'no data detected from source' notification was already shown, we prevent the
|
|
47
|
|
- // no audio signal notification as it's redundant i.e. it's clear that the users microphone is
|
|
48
|
|
- // muted from system settings.
|
|
49
|
|
- if (noSrcDataNotificationUid) {
|
|
50
|
|
- return;
|
|
51
|
|
- }
|
|
52
|
|
-
|
|
53
|
|
- // Force the flag to false in case AUDIO_INPUT_STATE_CHANGE is received after the notification is displayed,
|
|
54
|
|
- // possibly preventing the notification from displaying because of an outdated state.
|
|
55
|
|
- confAudioInputState = false;
|
|
56
|
|
-
|
|
57
|
|
-
|
|
58
|
|
- const activeDevice = await JitsiMeetJS.getActiveAudioDevice();
|
|
59
|
|
-
|
|
60
|
|
- if (confAudioInputState) {
|
|
61
|
|
- return;
|
|
62
|
|
- }
|
|
63
|
|
-
|
|
64
|
|
- // In case there is a previous notification displayed just hide it.
|
|
65
|
|
- const { noAudioSignalNotificationUid } = getState()['features/no-audio-signal'];
|
|
66
|
|
-
|
|
67
|
|
- if (noAudioSignalNotificationUid) {
|
|
68
|
|
- dispatch(hideNotification(noAudioSignalNotificationUid));
|
|
69
|
|
- dispatch(setNoAudioSignalNotificationUid());
|
|
70
|
|
- }
|
|
71
|
|
-
|
|
72
|
|
-
|
|
73
|
|
- let descriptionKey = 'toolbar.noAudioSignalDesc';
|
|
74
|
|
- let customActionNameKey;
|
|
75
|
|
- let customActionHandler;
|
|
76
|
|
-
|
|
77
|
|
- // In case the detector picked up a device show a notification with a device suggestion
|
|
78
|
|
- if (activeDevice.deviceLabel !== '') {
|
|
79
|
|
- descriptionKey = 'toolbar.noAudioSignalDescSuggestion';
|
|
80
|
|
-
|
|
81
|
|
- // Preferably the label should be passed as an argument paired with a i18next string, however
|
|
82
|
|
- // at the point of the implementation the showNotification function only supports doing that for
|
|
83
|
|
- // the description.
|
|
84
|
|
- // TODO Add support for arguments to showNotification title and customAction strings.
|
|
85
|
|
- customActionNameKey = `Use ${formatDeviceLabel(activeDevice.deviceLabel)}`;
|
|
86
|
|
- customActionHandler = () => {
|
|
87
|
|
- // Select device callback
|
|
88
|
|
- dispatch(
|
|
89
|
|
- updateSettings({
|
|
90
|
|
- userSelectedMicDeviceId: activeDevice.deviceId,
|
|
91
|
|
- userSelectedMicDeviceLabel: activeDevice.deviceLabel
|
|
92
|
|
- })
|
|
93
|
|
- );
|
|
94
|
|
-
|
|
95
|
|
- dispatch(setAudioInputDevice(activeDevice.deviceId));
|
|
96
|
|
- };
|
|
97
|
|
- }
|
|
98
|
|
-
|
|
99
|
|
- const notification = showNotification({
|
|
100
|
|
- titleKey: 'toolbar.noAudioSignalTitle',
|
|
101
|
|
- descriptionKey,
|
|
102
|
|
- customActionNameKey,
|
|
103
|
|
- customActionHandler
|
|
104
|
|
- });
|
|
105
|
|
-
|
|
106
|
|
- dispatch(notification);
|
|
107
|
|
-
|
|
108
|
|
- dispatch(playSound(NO_AUDIO_SIGNAL_SOUND_ID));
|
|
109
|
|
-
|
|
110
|
|
- // Store the current notification uid so we can check for this state and hide it in case
|
|
111
|
|
- // a new track was added, thus changing the context of the notification
|
|
112
|
|
- dispatch(setNoAudioSignalNotificationUid(notification.uid));
|
|
113
|
|
- });
|
|
|
30
|
+ case CONFERENCE_JOINED:
|
|
|
31
|
+ _handleNoAudioSignalNotification(store, action);
|
|
114
|
32
|
break;
|
|
115
|
33
|
}
|
|
116
|
|
- }
|
|
117
|
34
|
|
|
118
|
35
|
return result;
|
|
119
|
36
|
});
|
|
|
37
|
+
|
|
|
38
|
+/**
|
|
|
39
|
+ * Handles the logic of displaying the no audio input detected notification as well as finding a valid device on the
|
|
|
40
|
+ * system.
|
|
|
41
|
+ *
|
|
|
42
|
+ * @param {Store} store - The redux store in which the specified action is being dispatched.
|
|
|
43
|
+ * @param {Action} action - The redux action {@code CONFERENCE_JOINED} which is being dispatched in the specified redux
|
|
|
44
|
+ * store.
|
|
|
45
|
+ * @private
|
|
|
46
|
+ * @returns {void}
|
|
|
47
|
+ */
|
|
|
48
|
+async function _handleNoAudioSignalNotification({ dispatch, getState }, action) {
|
|
|
49
|
+
|
|
|
50
|
+ const { conference } = action;
|
|
|
51
|
+ let confAudioInputState;
|
|
|
52
|
+
|
|
|
53
|
+ conference.on(JitsiConferenceEvents.AUDIO_INPUT_STATE_CHANGE, hasAudioInput => {
|
|
|
54
|
+ const { noAudioSignalNotificationUid } = getState()['features/no-audio-signal'];
|
|
|
55
|
+
|
|
|
56
|
+ confAudioInputState = hasAudioInput;
|
|
|
57
|
+
|
|
|
58
|
+ // In case the notification is displayed but the conference detected audio input signal we hide it.
|
|
|
59
|
+ if (noAudioSignalNotificationUid && hasAudioInput) {
|
|
|
60
|
+ dispatch(hideNotification(noAudioSignalNotificationUid));
|
|
|
61
|
+ dispatch(setNoAudioSignalNotificationUid());
|
|
|
62
|
+ }
|
|
|
63
|
+ });
|
|
|
64
|
+ conference.on(JitsiConferenceEvents.NO_AUDIO_INPUT, async () => {
|
|
|
65
|
+ const { noSrcDataNotificationUid } = getState()['features/base/no-src-data'];
|
|
|
66
|
+
|
|
|
67
|
+ // In case the 'no data detected from source' notification was already shown, we prevent the
|
|
|
68
|
+ // no audio signal notification as it's redundant i.e. it's clear that the users microphone is
|
|
|
69
|
+ // muted from system settings.
|
|
|
70
|
+ if (noSrcDataNotificationUid) {
|
|
|
71
|
+ return;
|
|
|
72
|
+ }
|
|
|
73
|
+
|
|
|
74
|
+ // Force the flag to false in case AUDIO_INPUT_STATE_CHANGE is received after the notification is displayed,
|
|
|
75
|
+ // possibly preventing the notification from displaying because of an outdated state.
|
|
|
76
|
+ confAudioInputState = false;
|
|
|
77
|
+
|
|
|
78
|
+
|
|
|
79
|
+ const activeDevice = await JitsiMeetJS.getActiveAudioDevice();
|
|
|
80
|
+
|
|
|
81
|
+ if (confAudioInputState) {
|
|
|
82
|
+ return;
|
|
|
83
|
+ }
|
|
|
84
|
+
|
|
|
85
|
+ // In case there is a previous notification displayed just hide it.
|
|
|
86
|
+ const { noAudioSignalNotificationUid } = getState()['features/no-audio-signal'];
|
|
|
87
|
+
|
|
|
88
|
+ if (noAudioSignalNotificationUid) {
|
|
|
89
|
+ dispatch(hideNotification(noAudioSignalNotificationUid));
|
|
|
90
|
+ dispatch(setNoAudioSignalNotificationUid());
|
|
|
91
|
+ }
|
|
|
92
|
+
|
|
|
93
|
+
|
|
|
94
|
+ let descriptionKey = 'toolbar.noAudioSignalDesc';
|
|
|
95
|
+ let customActionNameKey;
|
|
|
96
|
+ let customActionHandler;
|
|
|
97
|
+
|
|
|
98
|
+ // In case the detector picked up a device show a notification with a device suggestion
|
|
|
99
|
+ if (activeDevice.deviceLabel !== '') {
|
|
|
100
|
+ descriptionKey = 'toolbar.noAudioSignalDescSuggestion';
|
|
|
101
|
+
|
|
|
102
|
+ // Preferably the label should be passed as an argument paired with a i18next string, however
|
|
|
103
|
+ // at the point of the implementation the showNotification function only supports doing that for
|
|
|
104
|
+ // the description.
|
|
|
105
|
+ // TODO Add support for arguments to showNotification title and customAction strings.
|
|
|
106
|
+ customActionNameKey = `Use ${formatDeviceLabel(activeDevice.deviceLabel)}`;
|
|
|
107
|
+ customActionHandler = () => {
|
|
|
108
|
+ // Select device callback
|
|
|
109
|
+ dispatch(
|
|
|
110
|
+ updateSettings({
|
|
|
111
|
+ userSelectedMicDeviceId: activeDevice.deviceId,
|
|
|
112
|
+ userSelectedMicDeviceLabel: activeDevice.deviceLabel
|
|
|
113
|
+ })
|
|
|
114
|
+ );
|
|
|
115
|
+
|
|
|
116
|
+ dispatch(setAudioInputDevice(activeDevice.deviceId));
|
|
|
117
|
+ };
|
|
|
118
|
+ }
|
|
|
119
|
+
|
|
|
120
|
+ const notification = showNotification({
|
|
|
121
|
+ titleKey: 'toolbar.noAudioSignalTitle',
|
|
|
122
|
+ descriptionKey,
|
|
|
123
|
+ customActionNameKey,
|
|
|
124
|
+ customActionHandler
|
|
|
125
|
+ });
|
|
|
126
|
+
|
|
|
127
|
+ dispatch(notification);
|
|
|
128
|
+
|
|
|
129
|
+ dispatch(playSound(NO_AUDIO_SIGNAL_SOUND_ID));
|
|
|
130
|
+
|
|
|
131
|
+ // Store the current notification uid so we can check for this state and hide it in case
|
|
|
132
|
+ // a new track was added, thus changing the context of the notification
|
|
|
133
|
+ dispatch(setNoAudioSignalNotificationUid(notification.uid));
|
|
|
134
|
+ });
|
|
|
135
|
+}
|