Преглед изворни кода

feat(invite-sounds): Add expired and rejected sounds.

j8
hristoterezov пре 7 година
родитељ
комит
d89227829f

+ 22
- 0
react/features/base/participants/functions.js Прегледај датотеку

@@ -180,6 +180,28 @@ export function getParticipantDisplayName(
180 180
         : 'Fellow Jitster';
181 181
 }
182 182
 
183
+/**
184
+ * Returns the presence status of a participant associated with the passed id.
185
+ *
186
+ * @param {(Function|Object)} stateful - The (whole) redux state, or redux's
187
+ * {@code getState} function to be used to retrieve the state.
188
+ * @param {string} id - The id of the participant.
189
+ * @returns {string} - The presence status.
190
+ */
191
+export function getParticipantPresenceStatus(
192
+        stateful: Object | Function, id: string) {
193
+    if (!id) {
194
+        return undefined;
195
+    }
196
+    const participantById = getParticipantById(stateful, id);
197
+
198
+    if (!participantById) {
199
+        return undefined;
200
+    }
201
+
202
+    return participantById.presence;
203
+}
204
+
183 205
 /**
184 206
  * Selectors for getting all known participants with fake participants filtered
185 207
  * out.

+ 18
- 0
react/features/invite/constants.js Прегледај датотеку

@@ -1,3 +1,21 @@
1
+/**
2
+ * The identifier of the sound to be played when the status of an outgoing call
3
+ * is expired.
4
+ *
5
+ * @type {string}
6
+ */
7
+export const OUTGOING_CALL_EXPIRED_SOUND_ID
8
+    = 'OUTGOING_CALL_EXPIRED_SOUND_ID';
9
+
10
+/**
11
+ * The identifier of the sound to be played when the status of an outgoing call
12
+ * is rejected.
13
+ *
14
+ * @type {string}
15
+ */
16
+export const OUTGOING_CALL_REJECTED_SOUND_ID
17
+    = 'OUTGOING_CALL_REJECTED_SOUND_ID';
18
+
1 19
 /**
2 20
  * The identifier of the sound to be played when the status of an outgoing call
3 21
  * is ringing.

+ 52
- 56
react/features/invite/middleware.any.js Прегледај датотеку

@@ -2,9 +2,10 @@
2 2
 
3 3
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
4 4
 import {
5
-    getParticipantById,
6
-    PARTICIPANT_UPDATED,
7
-    PARTICIPANT_LEFT
5
+    getParticipantPresenceStatus,
6
+    PARTICIPANT_JOINED_SOUND_ID,
7
+    PARTICIPANT_LEFT,
8
+    PARTICIPANT_UPDATED
8 9
 } from '../base/participants';
9 10
 import { MiddlewareRegistry } from '../base/redux';
10 11
 import {
@@ -15,24 +16,39 @@ import {
15 16
 } from '../base/sounds';
16 17
 import {
17 18
     CALLING,
19
+    CONNECTED_USER,
20
+    EXPIRED,
18 21
     INVITED,
22
+    REJECTED,
19 23
     RINGING
20 24
 } from '../presence-status';
21 25
 
22 26
 import { UPDATE_DIAL_IN_NUMBERS_FAILED } from './actionTypes';
23 27
 import {
24
-    OUTGOING_CALL_START_SOUND_ID,
25
-    OUTGOING_CALL_RINGING_SOUND_ID
28
+    OUTGOING_CALL_EXPIRED_SOUND_ID,
29
+    OUTGOING_CALL_REJECTED_SOUND_ID,
30
+    OUTGOING_CALL_RINGING_SOUND_ID,
31
+    OUTGOING_CALL_START_SOUND_ID
26 32
 } from './constants';
27
-import {
28
-    OUTGOING_CALL_START_FILE,
29
-    OUTGOING_CALL_RINGING_FILE
30
-} from './sounds';
33
+import { sounds } from './sounds';
31 34
 
32 35
 const logger = require('jitsi-meet-logger').getLogger(__filename);
33 36
 
34 37
 declare var interfaceConfig: Object;
35 38
 
39
+/**
40
+ * Maps the presence status with the ID of the sound that will be played when
41
+ * the status is received.
42
+ */
43
+const statusToRingtone = {
44
+    [CALLING]: OUTGOING_CALL_START_SOUND_ID,
45
+    [CONNECTED_USER]: PARTICIPANT_JOINED_SOUND_ID,
46
+    [EXPIRED]: OUTGOING_CALL_EXPIRED_SOUND_ID,
47
+    [INVITED]: OUTGOING_CALL_START_SOUND_ID,
48
+    [REJECTED]: OUTGOING_CALL_REJECTED_SOUND_ID,
49
+    [RINGING]: OUTGOING_CALL_RINGING_SOUND_ID
50
+};
51
+
36 52
 /**
37 53
  * The middleware of the feature invite common to mobile/react-native and
38 54
  * Web/React.
@@ -46,56 +62,55 @@ MiddlewareRegistry.register(store => next => action => {
46 62
     if (action.type === PARTICIPANT_UPDATED
47 63
         || action.type === PARTICIPANT_LEFT) {
48 64
         oldParticipantPresence
49
-            = _getParticipantPresence(store.getState(), action.participant.id);
65
+            = getParticipantPresenceStatus(
66
+                store.getState(),
67
+                action.participant.id);
50 68
     }
51 69
 
52 70
     const result = next(action);
53 71
 
54 72
     switch (action.type) {
55 73
     case APP_WILL_MOUNT:
56
-        store.dispatch(
57
-            registerSound(
58
-                OUTGOING_CALL_START_SOUND_ID,
59
-                OUTGOING_CALL_START_FILE));
60
-
61
-        store.dispatch(
62
-            registerSound(
63
-                OUTGOING_CALL_RINGING_SOUND_ID,
64
-                OUTGOING_CALL_RINGING_FILE,
65
-                { loop: true }));
74
+        for (const [ soundId, sound ] of sounds.entries()) {
75
+            store.dispatch(registerSound(soundId, sound.file, sound.options));
76
+        }
66 77
         break;
67 78
 
68 79
     case APP_WILL_UNMOUNT:
69
-        store.dispatch(unregisterSound(OUTGOING_CALL_START_SOUND_ID));
70
-        store.dispatch(unregisterSound(OUTGOING_CALL_RINGING_SOUND_ID));
80
+        for (const soundId of sounds.keys()) {
81
+            store.dispatch(unregisterSound(soundId));
82
+        }
71 83
         break;
72 84
 
73 85
     case PARTICIPANT_LEFT:
74 86
     case PARTICIPANT_UPDATED: {
75 87
         const newParticipantPresence
76
-            = _getParticipantPresence(store.getState(), action.participant.id);
88
+            = getParticipantPresenceStatus(
89
+                store.getState(),
90
+                action.participant.id);
77 91
 
78 92
         if (oldParticipantPresence === newParticipantPresence) {
79 93
             break;
80 94
         }
81 95
 
82
-        switch (oldParticipantPresence) {
83
-        case CALLING:
84
-        case INVITED:
85
-            store.dispatch(stopSound(OUTGOING_CALL_START_SOUND_ID));
86
-            break;
87
-        case RINGING:
88
-            store.dispatch(stopSound(OUTGOING_CALL_RINGING_SOUND_ID));
96
+        const oldSoundId
97
+            = oldParticipantPresence
98
+                && statusToRingtone[oldParticipantPresence];
99
+        const newSoundId
100
+            = newParticipantPresence
101
+                && statusToRingtone[newParticipantPresence];
102
+
103
+
104
+        if (oldSoundId === newSoundId) {
89 105
             break;
90 106
         }
91 107
 
92
-        switch (newParticipantPresence) {
93
-        case CALLING:
94
-        case INVITED:
95
-            store.dispatch(playSound(OUTGOING_CALL_START_SOUND_ID));
96
-            break;
97
-        case RINGING:
98
-            store.dispatch(playSound(OUTGOING_CALL_RINGING_SOUND_ID));
108
+        if (oldSoundId) {
109
+            store.dispatch(stopSound(oldSoundId));
110
+        }
111
+
112
+        if (newSoundId) {
113
+            store.dispatch(playSound(newSoundId));
99 114
         }
100 115
 
101 116
         break;
@@ -109,22 +124,3 @@ MiddlewareRegistry.register(store => next => action => {
109 124
 
110 125
     return result;
111 126
 });
112
-
113
-/**
114
- * Returns the presence status of a participant associated with the passed id.
115
- *
116
- * @param {Object} state - The redux state.
117
- * @param {string} id - The id of the participant.
118
- * @returns {string} - The presence status.
119
- */
120
-function _getParticipantPresence(state, id) {
121
-    if (id) {
122
-        const participantById = getParticipantById(state, id);
123
-
124
-        if (participantById) {
125
-            return participantById.presence;
126
-        }
127
-    }
128
-
129
-    return undefined;
130
-}

+ 41
- 8
react/features/invite/sounds.js Прегледај датотеку

@@ -1,11 +1,44 @@
1
-/**
2
- * The name of the sound file which will be played when the status of an
3
- * outgoing call is ringing.
4
- */
5
-export const OUTGOING_CALL_RINGING_FILE = 'outgoingRinging.wav';
1
+import {
2
+    OUTGOING_CALL_EXPIRED_SOUND_ID,
3
+    OUTGOING_CALL_REJECTED_SOUND_ID,
4
+    OUTGOING_CALL_RINGING_SOUND_ID,
5
+    OUTGOING_CALL_START_SOUND_ID
6
+} from './constants';
6 7
 
7 8
 /**
8
- * The name of the sound file which will be played when outgoing call is
9
- * started.
9
+ * Maps the sounds IDs with the filenames sounds associated with them.
10
+ *
11
+ * @type {Map<string, string>}
10 12
  */
11
-export const OUTGOING_CALL_START_FILE = 'outgoingStart.wav';
13
+export const sounds = new Map([
14
+
15
+    /**
16
+     * The name of the sound file which will be played when outgoing call is
17
+     * expired.
18
+     */
19
+    [ OUTGOING_CALL_EXPIRED_SOUND_ID, { file: 'rejected.wav' } ],
20
+
21
+    /**
22
+     * The name of the sound file which will be played when outgoing call is
23
+     * rejected.
24
+     */
25
+    [ OUTGOING_CALL_REJECTED_SOUND_ID, { file: 'rejected.wav' } ],
26
+
27
+    /**
28
+     * The name of the sound file which will be played when the status of an
29
+     * outgoing call is ringing.
30
+     */
31
+    [
32
+        OUTGOING_CALL_RINGING_SOUND_ID,
33
+        {
34
+            file: 'outgoingRinging.wav',
35
+            options: { loop: true }
36
+        }
37
+    ],
38
+
39
+    /**
40
+     * The name of the sound file which will be played when outgoing call is
41
+     * started.
42
+     */
43
+    [ OUTGOING_CALL_START_SOUND_ID, { file: 'outgoingStart.wav' } ]
44
+]);

BIN
sounds/rejected.wav Прегледај датотеку


Loading…
Откажи
Сачувај