Procházet zdrojové kódy

fix(lastn) debounce updating last N

When joining a large meeting every participant join would trigger an attempt of
an update. Try to minimize the amount of calls.
master
Saúl Ibarra Corretgé před 3 roky
rodič
revize
a687907105
1 změnil soubory, kde provedl 33 přidání a 31 odebrání
  1. 33
    31
      react/features/base/lastn/middleware.js

+ 33
- 31
react/features/base/lastn/middleware.js Zobrazit soubor

@@ -1,5 +1,7 @@
1 1
 // @flow
2 2
 
3
+import debounce from 'lodash/debounce';
4
+
3 5
 import { SET_FILMSTRIP_ENABLED } from '../../filmstrip/actionTypes';
4 6
 import { SELECT_LARGE_VIDEO_PARTICIPANT } from '../../large-video/actionTypes';
5 7
 import { APP_STATE_CHANGED } from '../../mobile/background/actionTypes';
@@ -22,29 +24,6 @@ import { setLastN } from './actions';
22 24
 import { limitLastN } from './functions';
23 25
 import logger from './logger';
24 26
 
25
-declare var APP: Object;
26
-
27
-MiddlewareRegistry.register(store => next => action => {
28
-    const result = next(action);
29
-
30
-    switch (action.type) {
31
-    case APP_STATE_CHANGED:
32
-    case CONFERENCE_JOINED:
33
-    case PARTICIPANT_JOINED:
34
-    case PARTICIPANT_KICKED:
35
-    case PARTICIPANT_LEFT:
36
-    case SCREEN_SHARE_REMOTE_PARTICIPANTS_UPDATED:
37
-    case SELECT_LARGE_VIDEO_PARTICIPANT:
38
-    case SET_AUDIO_ONLY:
39
-    case SET_FILMSTRIP_ENABLED:
40
-    case SET_TILE_VIEW:
41
-        _updateLastN(store);
42
-        break;
43
-    }
44
-
45
-    return result;
46
-});
47
-
48 27
 /**
49 28
  * Updates the last N value in the conference based on the current state of the redux store.
50 29
  *
@@ -52,15 +31,9 @@ MiddlewareRegistry.register(store => next => action => {
52 31
  * @private
53 32
  * @returns {void}
54 33
  */
55
-function _updateLastN({ dispatch, getState }) {
34
+const _updateLastN = debounce(({ dispatch, getState }) => {
56 35
     const state = getState();
57 36
     const { conference } = state['features/base/conference'];
58
-    const { enabled: audioOnly } = state['features/base/audio-only'];
59
-    const { appState } = state['features/background'] || {};
60
-    const { enabled: filmStripEnabled } = state['features/filmstrip'];
61
-    const config = state['features/base/config'];
62
-    const { lastNLimits, lastN } = state['features/base/lastn'];
63
-    const participantCount = getParticipantCount(state);
64 37
 
65 38
     if (!conference) {
66 39
         logger.debug('There is no active conference, not updating last N');
@@ -68,6 +41,13 @@ function _updateLastN({ dispatch, getState }) {
68 41
         return;
69 42
     }
70 43
 
44
+    const { enabled: audioOnly } = state['features/base/audio-only'];
45
+    const { appState } = state['features/background'] || {};
46
+    const { enabled: filmStripEnabled } = state['features/filmstrip'];
47
+    const config = state['features/base/config'];
48
+    const { lastNLimits, lastN } = state['features/base/lastn'];
49
+    const participantCount = getParticipantCount(state);
50
+
71 51
     // Select the lastN value based on the following preference order.
72 52
     // 1. The last-n value in redux.
73 53
     // 2. The last-n value from 'startLastN' if it is specified in config.js
@@ -104,4 +84,26 @@ function _updateLastN({ dispatch, getState }) {
104 84
 
105 85
     logger.info(`Setting last N to: ${lastNSelected}`);
106 86
     dispatch(setLastN(lastNSelected));
107
-}
87
+}, 1000); /* Don't send this more often than once a second. */
88
+
89
+
90
+MiddlewareRegistry.register(store => next => action => {
91
+    const result = next(action);
92
+
93
+    switch (action.type) {
94
+    case APP_STATE_CHANGED:
95
+    case CONFERENCE_JOINED:
96
+    case PARTICIPANT_JOINED:
97
+    case PARTICIPANT_KICKED:
98
+    case PARTICIPANT_LEFT:
99
+    case SCREEN_SHARE_REMOTE_PARTICIPANTS_UPDATED:
100
+    case SELECT_LARGE_VIDEO_PARTICIPANT:
101
+    case SET_AUDIO_ONLY:
102
+    case SET_FILMSTRIP_ENABLED:
103
+    case SET_TILE_VIEW:
104
+        _updateLastN(store);
105
+        break;
106
+    }
107
+
108
+    return result;
109
+});

Načítá se…
Zrušit
Uložit