Kaynağa Gözat

Fix accidental overwrite of localParticipant with empty values

master
zbettenbuk 7 yıl önce
ebeveyn
işleme
cc7e15ab8f
1 değiştirilmiş dosya ile 33 ekleme ve 15 silme
  1. 33
    15
      react/features/base/settings/middleware.js

+ 33
- 15
react/features/base/settings/middleware.js Dosyayı Görüntüle

@@ -2,10 +2,9 @@
2 2
 
3 3
 import { setAudioOnly } from '../conference';
4 4
 import { getLocalParticipant, participantUpdated } from '../participants';
5
-import { MiddlewareRegistry, toState } from '../redux';
5
+import { MiddlewareRegistry } from '../redux';
6 6
 
7 7
 import { SETTINGS_UPDATED } from './actionTypes';
8
-import { getSettings } from './functions';
9 8
 
10 9
 /**
11 10
  * The middleware of the feature base/settings. Distributes changes to the state
@@ -21,12 +20,29 @@ MiddlewareRegistry.register(store => next => action => {
21 20
     switch (action.type) {
22 21
     case SETTINGS_UPDATED:
23 22
         _maybeSetAudioOnly(store, action);
24
-        _updateLocalParticipant(store);
23
+        _updateLocalParticipant(store, action);
25 24
     }
26 25
 
27 26
     return result;
28 27
 });
29 28
 
29
+/**
30
+ * Maps the settings field names to participant names where they don't match.
31
+ * Currently there is only one such field, but may be extended in the future.
32
+ *
33
+ * @private
34
+ * @param {string} settingsField - The name of the settings field to map.
35
+ * @returns {string}
36
+ */
37
+function _mapSettingsFieldToParticipant(settingsField) {
38
+    switch (settingsField) {
39
+    case 'displayName':
40
+        return 'name';
41
+    }
42
+
43
+    return settingsField;
44
+}
45
+
30 46
 /**
31 47
  * Updates {@code startAudioOnly} flag if it's updated in the settings.
32 48
  *
@@ -47,21 +63,23 @@ function _maybeSetAudioOnly(
47 63
  * Updates the local participant according to settings changes.
48 64
  *
49 65
  * @param {Store} store - The redux store.
66
+ * @param {Object} action - The dispatched action.
50 67
  * @private
51 68
  * @returns {void}
52 69
  */
53
-function _updateLocalParticipant(store) {
54
-    const state = toState(store);
55
-    const localParticipant = getLocalParticipant(state);
56
-    const settings = getSettings(state);
70
+function _updateLocalParticipant({ dispatch, getState }, action) {
71
+    const { settings } = action;
72
+    const localParticipant = getLocalParticipant(getState());
73
+    const newLocalParticipant = {
74
+        ...localParticipant
75
+    };
57 76
 
58
-    store.dispatch(participantUpdated({
59
-        // Identify that the participant to update i.e. the local participant:
60
-        id: localParticipant && localParticipant.id,
61
-        local: true,
77
+    for (const key in settings) {
78
+        if (settings.hasOwnProperty(key)) {
79
+            newLocalParticipant[_mapSettingsFieldToParticipant(key)]
80
+                = settings[key];
81
+        }
82
+    }
62 83
 
63
-        // Specify the updates to be applied to the identified participant:
64
-        email: settings.email,
65
-        name: settings.displayName
66
-    }));
84
+    dispatch(participantUpdated(newLocalParticipant));
67 85
 }

Loading…
İptal
Kaydet