|
@@ -3,14 +3,10 @@ import { setNoAudioSignalNotificationUid } from './actions';
|
3
|
3
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
|
4
|
4
|
import { CONFERENCE_JOINED } from '../base/conference';
|
5
|
5
|
import {
|
6
|
|
- ACTIVE_DEVICE_DETECTED,
|
7
|
|
- ActiveDeviceDetector,
|
8
|
|
- filterAudioDevices,
|
9
|
6
|
formatDeviceLabel,
|
10
|
|
- getAvailableDevices,
|
11
|
7
|
setAudioInputDevice
|
12
|
8
|
} from '../base/devices';
|
13
|
|
-import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
|
9
|
+import JitsiMeetJS, { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
|
14
|
10
|
import { MiddlewareRegistry } from '../base/redux';
|
15
|
11
|
import { updateSettings } from '../base/settings';
|
16
|
12
|
import { playSound, registerSound, unregisterSound } from '../base/sounds';
|
|
@@ -22,7 +18,7 @@ MiddlewareRegistry.register(store => next => async action => {
|
22
|
18
|
const result = next(action);
|
23
|
19
|
const { dispatch, getState } = store;
|
24
|
20
|
const { conference } = action;
|
25
|
|
- let audioDetectService = null;
|
|
21
|
+ let confAudioInputState;
|
26
|
22
|
|
27
|
23
|
switch (action.type) {
|
28
|
24
|
case APP_WILL_MOUNT:
|
|
@@ -33,84 +29,86 @@ MiddlewareRegistry.register(store => next => async action => {
|
33
|
29
|
break;
|
34
|
30
|
|
35
|
31
|
case CONFERENCE_JOINED: {
|
36
|
|
- conference.on(JitsiConferenceEvents.TRACK_ADDED, track => {
|
|
32
|
+ conference.on(JitsiConferenceEvents.AUDIO_INPUT_STATE_CHANGE, hasAudioInput => {
|
37
|
33
|
const { noAudioSignalNotificationUid } = getState()['features/no-audio-signal'];
|
38
|
34
|
|
39
|
|
- if (track.isAudioTrack() && track.isLocal()) {
|
40
|
|
- // In case the device is switched attempt to destroy, this should prevent the notification firing
|
41
|
|
- // when the device was switched, however it is possible that a user switches the device and the
|
42
|
|
- // notification from the previous devices pops up, but this will probably happen very rarely and even
|
43
|
|
- // if it does it's not that disruptive to the ux.
|
44
|
|
- if (audioDetectService) {
|
45
|
|
- audioDetectService.destroy();
|
46
|
|
- audioDetectService = null;
|
47
|
|
- }
|
48
|
|
-
|
49
|
|
- // When a new track is added hide the current notification is one is displayed, and reset the redux
|
50
|
|
- // state so that we begin monitoring on the new device as well.
|
51
|
|
- if (noAudioSignalNotificationUid) {
|
52
|
|
- dispatch(hideNotification(noAudioSignalNotificationUid));
|
53
|
|
- dispatch(setNoAudioSignalNotificationUid());
|
54
|
|
- }
|
|
35
|
+ confAudioInputState = hasAudioInput;
|
|
36
|
+
|
|
37
|
+ if (noAudioSignalNotificationUid && hasAudioInput) {
|
|
38
|
+ dispatch(hideNotification(noAudioSignalNotificationUid));
|
|
39
|
+ dispatch(setNoAudioSignalNotificationUid());
|
55
|
40
|
}
|
56
|
41
|
});
|
57
|
42
|
conference.on(JitsiConferenceEvents.NO_AUDIO_INPUT, async () => {
|
58
|
|
- const { noSrcDataNotiUid } = getState()['features/base/no-src-data'];
|
|
43
|
+ const { noSrcDataNotificationUid } = getState()['features/base/no-src-data'];
|
59
|
44
|
|
60
|
45
|
// In case the 'no data detected from source' notification was already shown, we prevent the
|
61
|
46
|
// no audio signal notification as it's redundant i.e. it's clear that the users microphone is
|
62
|
47
|
// muted from system settings.
|
63
|
|
- if (noSrcDataNotiUid) {
|
|
48
|
+ if (noSrcDataNotificationUid) {
|
64
|
49
|
return;
|
65
|
50
|
}
|
66
|
51
|
|
67
|
|
- const devices = await dispatch(getAvailableDevices());
|
68
|
|
- const audioDevices = filterAudioDevices(devices);
|
69
|
|
-
|
70
|
|
- audioDetectService = await ActiveDeviceDetector.create(audioDevices);
|
71
|
|
-
|
72
|
|
- audioDetectService.on(ACTIVE_DEVICE_DETECTED, detectEvent => {
|
73
|
|
- let descriptionKey = 'toolbar.noAudioSignalDesc';
|
74
|
|
- let customActionNameKey = null;
|
75
|
|
- let customActionHandler = null;
|
76
|
|
-
|
77
|
|
- // In case the detector picked up a device show a notification with a device suggestion
|
78
|
|
- if (detectEvent.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(detectEvent.deviceLabel)}`;
|
86
|
|
- customActionHandler = () => {
|
87
|
|
- // Select device callback
|
88
|
|
- dispatch(
|
89
|
|
- updateSettings({
|
90
|
|
- userSelectedMicDeviceId: detectEvent.deviceId,
|
91
|
|
- userSelectedMicDeviceLabel: detectEvent.deviceLabel
|
92
|
|
- })
|
93
|
|
- );
|
94
|
|
-
|
95
|
|
- dispatch(setAudioInputDevice(detectEvent.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));
|
|
52
|
+ // Force the flag to false in case AUDIO_INPUT_STATE_CHANGE is received after the notification is displayed,
|
|
53
|
+ // thus making sure we check properly if the notification should display.
|
|
54
|
+ confAudioInputState = false;
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+ const activeDevice = await JitsiMeetJS.getActiveAudioDevice();
|
|
58
|
+
|
|
59
|
+ if (confAudioInputState) {
|
|
60
|
+ return;
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ // In case there is a previous notification displayed just hide it.
|
|
64
|
+ const { noAudioSignalNotificationUid } = getState()['features/no-audio-signal'];
|
|
65
|
+
|
|
66
|
+ if (noAudioSignalNotificationUid) {
|
|
67
|
+ dispatch(hideNotification(noAudioSignalNotificationUid));
|
|
68
|
+ dispatch(setNoAudioSignalNotificationUid());
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+ let descriptionKey = 'toolbar.noAudioSignalDesc';
|
|
73
|
+ let customActionNameKey;
|
|
74
|
+ let customActionHandler;
|
|
75
|
+
|
|
76
|
+ // In case the detector picked up a device show a notification with a device suggestion
|
|
77
|
+ if (activeDevice.deviceLabel !== '') {
|
|
78
|
+ descriptionKey = 'toolbar.noAudioSignalDescSuggestion';
|
|
79
|
+
|
|
80
|
+ // Preferably the label should be passed as an argument paired with a i18next string, however
|
|
81
|
+ // at the point of the implementation the showNotification function only supports doing that for
|
|
82
|
+ // the description.
|
|
83
|
+ // TODO Add support for arguments to showNotification title and customAction strings.
|
|
84
|
+ customActionNameKey = `Use ${formatDeviceLabel(activeDevice.deviceLabel)}`;
|
|
85
|
+ customActionHandler = () => {
|
|
86
|
+ // Select device callback
|
|
87
|
+ dispatch(
|
|
88
|
+ updateSettings({
|
|
89
|
+ userSelectedMicDeviceId: activeDevice.deviceId,
|
|
90
|
+ userSelectedMicDeviceLabel: activeDevice.deviceLabel
|
|
91
|
+ })
|
|
92
|
+ );
|
|
93
|
+
|
|
94
|
+ dispatch(setAudioInputDevice(activeDevice.deviceId));
|
|
95
|
+ };
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ const notification = showNotification({
|
|
99
|
+ titleKey: 'toolbar.noAudioSignalTitle',
|
|
100
|
+ descriptionKey,
|
|
101
|
+ customActionNameKey,
|
|
102
|
+ customActionHandler
|
113
|
103
|
});
|
|
104
|
+
|
|
105
|
+ dispatch(notification);
|
|
106
|
+
|
|
107
|
+ dispatch(playSound(NO_AUDIO_SIGNAL_SOUND_ID));
|
|
108
|
+
|
|
109
|
+ // Store the current notification uid so we can check for this state and hide it in case
|
|
110
|
+ // a new track was added, thus changing the context of the notification
|
|
111
|
+ dispatch(setNoAudioSignalNotificationUid(notification.uid));
|
114
|
112
|
});
|
115
|
113
|
break;
|
116
|
114
|
}
|