浏览代码

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é 3 年前
父节点
当前提交
a687907105
共有 1 个文件被更改,包括 33 次插入31 次删除
  1. 33
    31
      react/features/base/lastn/middleware.js

+ 33
- 31
react/features/base/lastn/middleware.js 查看文件

1
 // @flow
1
 // @flow
2
 
2
 
3
+import debounce from 'lodash/debounce';
4
+
3
 import { SET_FILMSTRIP_ENABLED } from '../../filmstrip/actionTypes';
5
 import { SET_FILMSTRIP_ENABLED } from '../../filmstrip/actionTypes';
4
 import { SELECT_LARGE_VIDEO_PARTICIPANT } from '../../large-video/actionTypes';
6
 import { SELECT_LARGE_VIDEO_PARTICIPANT } from '../../large-video/actionTypes';
5
 import { APP_STATE_CHANGED } from '../../mobile/background/actionTypes';
7
 import { APP_STATE_CHANGED } from '../../mobile/background/actionTypes';
22
 import { limitLastN } from './functions';
24
 import { limitLastN } from './functions';
23
 import logger from './logger';
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
  * Updates the last N value in the conference based on the current state of the redux store.
28
  * Updates the last N value in the conference based on the current state of the redux store.
50
  *
29
  *
52
  * @private
31
  * @private
53
  * @returns {void}
32
  * @returns {void}
54
  */
33
  */
55
-function _updateLastN({ dispatch, getState }) {
34
+const _updateLastN = debounce(({ dispatch, getState }) => {
56
     const state = getState();
35
     const state = getState();
57
     const { conference } = state['features/base/conference'];
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
     if (!conference) {
38
     if (!conference) {
66
         logger.debug('There is no active conference, not updating last N');
39
         logger.debug('There is no active conference, not updating last N');
68
         return;
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
     // Select the lastN value based on the following preference order.
51
     // Select the lastN value based on the following preference order.
72
     // 1. The last-n value in redux.
52
     // 1. The last-n value in redux.
73
     // 2. The last-n value from 'startLastN' if it is specified in config.js
53
     // 2. The last-n value from 'startLastN' if it is specified in config.js
104
 
84
 
105
     logger.info(`Setting last N to: ${lastNSelected}`);
85
     logger.info(`Setting last N to: ${lastNSelected}`);
106
     dispatch(setLastN(lastNSelected));
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
+});

正在加载...
取消
保存