Browse Source

Talk while muted sound notification (#4473)

* Moves talk while muted as a new feature.

* Adds sound notification for talk while muted.

* Reorder imports and changes the dispatch of the notification.

* Introduces sounds.js for talk while muted.
master
Дамян Минков 5 years ago
parent
commit
11f2e7291e
No account linked to committer's email address

+ 1
- 22
conference.js View File

@@ -78,10 +78,7 @@ import {
78 78
     setVideoAvailable,
79 79
     setVideoMuted
80 80
 } from './react/features/base/media';
81
-import {
82
-    hideNotification,
83
-    showNotification
84
-} from './react/features/notifications';
81
+import { showNotification } from './react/features/notifications';
85 82
 import {
86 83
     dominantSpeakerChanged,
87 84
     getLocalParticipant,
@@ -1798,30 +1795,12 @@ export default {
1798 1795
             APP.UI.setAudioLevel(id, newLvl);
1799 1796
         });
1800 1797
 
1801
-        // we store the last start muted notification id that we showed,
1802
-        // so we can hide it when unmuted mic is detected
1803
-        let lastNotificationId;
1804
-
1805 1798
         room.on(JitsiConferenceEvents.TRACK_MUTE_CHANGED, (track, participantThatMutedUs) => {
1806 1799
             if (participantThatMutedUs) {
1807 1800
                 APP.store.dispatch(participantMutedUs(participantThatMutedUs));
1808 1801
             }
1809
-
1810
-            if (lastNotificationId && track.isAudioTrack() && track.isLocal() && !track.isMuted()) {
1811
-                APP.store.dispatch(hideNotification(lastNotificationId));
1812
-                lastNotificationId = undefined;
1813
-            }
1814 1802
         });
1815 1803
 
1816
-        room.on(JitsiConferenceEvents.TALK_WHILE_MUTED, () => {
1817
-            const action = APP.store.dispatch(showNotification({
1818
-                titleKey: 'toolbar.talkWhileMutedPopup',
1819
-                customActionNameKey: 'notify.unmute',
1820
-                customActionHandler: muteLocalAudio.bind(this, false)
1821
-            }));
1822
-
1823
-            lastNotificationId = action.uid;
1824
-        });
1825 1804
         room.on(JitsiConferenceEvents.SUBJECT_CHANGED,
1826 1805
             subject => APP.store.dispatch(conferenceSubjectChanged(subject)));
1827 1806
 

+ 1
- 0
react/features/app/components/App.web.js View File

@@ -10,6 +10,7 @@ import '../../chat';
10 10
 import '../../external-api';
11 11
 import '../../power-monitor';
12 12
 import '../../room-lock';
13
+import '../../talk-while-muted';
13 14
 import '../../video-layout';
14 15
 
15 16
 import { AbstractApp } from './AbstractApp';

+ 12
- 0
react/features/talk-while-muted/actionTypes.js View File

@@ -0,0 +1,12 @@
1
+/**
2
+ * The type of Redux action which sets the pending notification UID
3
+ * to use it for when hiding the notification is necessary, or unsets it when
4
+ * undefined (or no param) is passed.
5
+ *
6
+ * {
7
+ *     type: SET_CURRENT_NOTIFICATION_UID,
8
+ *     uid: ?number
9
+ * }
10
+ * @public
11
+ */
12
+export const SET_CURRENT_NOTIFICATION_UID = 'SET_CURRENT_NOTIFICATION_UID';

+ 21
- 0
react/features/talk-while-muted/actions.js View File

@@ -0,0 +1,21 @@
1
+// @flow
2
+
3
+import { SET_CURRENT_NOTIFICATION_UID } from './actionTypes';
4
+
5
+/**
6
+ * Sets UID of the the pending notification to use it when hiding
7
+ * the notification is necessary, or unsets it when undefined (or no param) is
8
+ * passed.
9
+ *
10
+ * @param {?number} uid - The UID of the notification.
11
+ * @returns {{
12
+ *     type: SET_CURRENT_NOTIFICATION_UID,
13
+ *     uid: number
14
+ * }}
15
+ */
16
+export function setCurrentNotificationUid(uid: ?number) {
17
+    return {
18
+        type: SET_CURRENT_NOTIFICATION_UID,
19
+        uid
20
+    };
21
+}

+ 6
- 0
react/features/talk-while-muted/constants.js View File

@@ -0,0 +1,6 @@
1
+/**
2
+ * The identifier of the sound to be played when we got event for talking while muted.
3
+ *
4
+ * @type {string}
5
+ */
6
+export const TALK_WHILE_MUTED_SOUND_ID = 'TALK_WHILE_MUTED_SOUND_ID';

+ 4
- 0
react/features/talk-while-muted/index.js View File

@@ -0,0 +1,4 @@
1
+// @flow
2
+
3
+import './middleware';
4
+import './reducer';

+ 63
- 0
react/features/talk-while-muted/middleware.js View File

@@ -0,0 +1,63 @@
1
+// @flow
2
+
3
+import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
4
+import { CONFERENCE_JOINED } from '../base/conference';
5
+import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
6
+import { setAudioMuted } from '../base/media';
7
+import { MiddlewareRegistry } from '../base/redux';
8
+import { playSound, registerSound, unregisterSound } from '../base/sounds';
9
+import {
10
+    hideNotification,
11
+    showNotification
12
+} from '../notifications';
13
+
14
+import { setCurrentNotificationUid } from './actions';
15
+import { TALK_WHILE_MUTED_SOUND_ID } from './constants';
16
+import { TALK_WHILE_MUTED_SOUND_FILE } from './sounds';
17
+
18
+MiddlewareRegistry.register(store => next => action => {
19
+    const result = next(action);
20
+    const { dispatch, getState } = store;
21
+    const { conference } = action;
22
+
23
+    switch (action.type) {
24
+    case APP_WILL_MOUNT:
25
+        dispatch(registerSound(TALK_WHILE_MUTED_SOUND_ID, TALK_WHILE_MUTED_SOUND_FILE));
26
+        break;
27
+    case APP_WILL_UNMOUNT:
28
+        dispatch(unregisterSound(TALK_WHILE_MUTED_SOUND_ID));
29
+        break;
30
+
31
+    case CONFERENCE_JOINED: {
32
+        conference.on(
33
+            JitsiConferenceEvents.TRACK_MUTE_CHANGED,
34
+            track => {
35
+                const { currentNotificationUid } = getState()['features/talk-while-muted'];
36
+
37
+                if (currentNotificationUid && track.isAudioTrack() && track.isLocal() && !track.isMuted()) {
38
+                    dispatch(hideNotification(currentNotificationUid));
39
+                    dispatch(setCurrentNotificationUid());
40
+                }
41
+            });
42
+        conference.on(
43
+            JitsiConferenceEvents.TALK_WHILE_MUTED, () => {
44
+                const notification = showNotification({
45
+                    titleKey: 'toolbar.talkWhileMutedPopup',
46
+                    customActionNameKey: 'notify.unmute',
47
+                    customActionHandler: () => dispatch(setAudioMuted(false))
48
+                });
49
+
50
+                dispatch(notification);
51
+
52
+                dispatch(playSound(TALK_WHILE_MUTED_SOUND_ID));
53
+
54
+                // we store the last start muted notification id that we showed,
55
+                // so we can hide it when unmuted mic is detected
56
+                dispatch(setCurrentNotificationUid(notification.uid));
57
+            });
58
+        break;
59
+    }
60
+    }
61
+
62
+    return result;
63
+});

+ 17
- 0
react/features/talk-while-muted/reducer.js View File

@@ -0,0 +1,17 @@
1
+// @flow
2
+
3
+import { ReducerRegistry, set } from '../base/redux';
4
+
5
+import { SET_CURRENT_NOTIFICATION_UID } from './actionTypes';
6
+
7
+/**
8
+ * Reduces the redux actions of the feature talk while muted.
9
+ */
10
+ReducerRegistry.register('features/talk-while-muted', (state = { }, action) => {
11
+    switch (action.type) {
12
+    case SET_CURRENT_NOTIFICATION_UID:
13
+        return set(state, 'currentNotificationUid', action.uid);
14
+    }
15
+
16
+    return state;
17
+});

+ 6
- 0
react/features/talk-while-muted/sounds.js View File

@@ -0,0 +1,6 @@
1
+/**
2
+ * The file used for the talk while muted sound notification.
3
+ *
4
+ * @type {string}
5
+ */
6
+export const TALK_WHILE_MUTED_SOUND_FILE = 'talkWhileMuted.mp3';

BIN
sounds/talkWhileMuted.mp3 View File


+ 1
- 0
webpack.config.js View File

@@ -186,6 +186,7 @@ module.exports = [
186 186
 function devServerProxyBypass({ path }) {
187 187
     if (path.startsWith('/css/') || path.startsWith('/doc/')
188 188
             || path.startsWith('/fonts/') || path.startsWith('/images/')
189
+            || path.startsWith('/sounds/')
189 190
             || path.startsWith('/static/')) {
190 191
         return path;
191 192
     }

Loading…
Cancel
Save