Просмотр исходного кода

feat(video-quality): persist.

j8
Hristo Terezov 4 лет назад
Родитель
Сommit
25839b18d2

+ 4
- 2
react/features/video-quality/components/OverflowMenuVideoQualityItem.web.js Просмотреть файл

12
 } from '../../base/icons';
12
 } from '../../base/icons';
13
 import { connect } from '../../base/redux';
13
 import { connect } from '../../base/redux';
14
 import { VIDEO_QUALITY_LEVELS } from '../constants';
14
 import { VIDEO_QUALITY_LEVELS } from '../constants';
15
+import { findNearestQualityLevel } from '../functions';
15
 
16
 
16
 /**
17
 /**
17
  * A map of of selectable receive resolutions to corresponding icons.
18
  * A map of of selectable receive resolutions to corresponding icons.
69
      */
70
      */
70
     render() {
71
     render() {
71
         const { _audioOnly, _videoQuality } = this.props;
72
         const { _audioOnly, _videoQuality } = this.props;
72
-        const icon = _audioOnly || !_videoQuality
73
+        const videoQualityLevel = findNearestQualityLevel(_videoQuality);
74
+        const icon = _audioOnly || !videoQualityLevel
73
             ? IconVideoQualityAudioOnly
75
             ? IconVideoQualityAudioOnly
74
-            : VIDEO_QUALITY_TO_ICON[_videoQuality];
76
+            : VIDEO_QUALITY_TO_ICON[videoQualityLevel];
75
 
77
 
76
         return (
78
         return (
77
             <li
79
             <li

+ 6
- 3
react/features/video-quality/components/VideoQualitySlider.web.js Просмотреть файл

316
             return _sliderOptions.indexOf(audioOnlyOption);
316
             return _sliderOptions.indexOf(audioOnlyOption);
317
         }
317
         }
318
 
318
 
319
-        const matchingOption = _sliderOptions.find(
320
-            ({ videoQuality }) => videoQuality === _sendrecvVideoQuality);
319
+        for (let i = 0; i < _sliderOptions.length; i++) {
320
+            if (_sliderOptions[i].videoQuality >= _sendrecvVideoQuality) {
321
+                return i;
322
+            }
323
+        }
321
 
324
 
322
-        return _sliderOptions.indexOf(matchingOption);
325
+        return -1;
323
     }
326
     }
324
 
327
 
325
     _onSliderChange: () => void;
328
     _onSliderChange: () => void;

+ 20
- 0
react/features/video-quality/functions.js Просмотреть файл

2
 
2
 
3
 import { CFG_LVL_TO_APP_QUALITY_LVL, VIDEO_QUALITY_LEVELS } from './constants';
3
 import { CFG_LVL_TO_APP_QUALITY_LVL, VIDEO_QUALITY_LEVELS } from './constants';
4
 
4
 
5
+const { LOW, STANDARD, HIGH } = VIDEO_QUALITY_LEVELS;
6
+const videoQualityLevels = [ LOW, STANDARD, HIGH ];
7
+
8
+/**
9
+ * Finds the nearest video quality level to the passed video quality.
10
+ *
11
+ * @param {number} videoQuality - The video quality.
12
+ * @returns {number|undefined} - The found quality level.
13
+ */
14
+export function findNearestQualityLevel(videoQuality: number) {
15
+    for (let i = 0; i < videoQualityLevels.length; i++) {
16
+        const level = videoQualityLevels[i];
17
+
18
+        if (level >= videoQuality) {
19
+            return level;
20
+        }
21
+    }
22
+
23
+    return undefined;
24
+}
5
 
25
 
6
 /**
26
 /**
7
  * Selects {@code VIDEO_QUALITY_LEVELS} for the given {@link availableHeight} and threshold to quality mapping.
27
  * Selects {@code VIDEO_QUALITY_LEVELS} for the given {@link availableHeight} and threshold to quality mapping.

+ 13
- 0
react/features/video-quality/middleware.js Просмотреть файл

4
     CONFERENCE_JOINED,
4
     CONFERENCE_JOINED,
5
     DATA_CHANNEL_OPENED
5
     DATA_CHANNEL_OPENED
6
 } from '../base/conference';
6
 } from '../base/conference';
7
+import { SET_CONFIG } from '../base/config';
7
 import { getParticipantCount } from '../base/participants';
8
 import { getParticipantCount } from '../base/participants';
8
 import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
9
 import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
9
 import { shouldDisplayTileView } from '../video-layout';
10
 import { shouldDisplayTileView } from '../video-layout';
39
         }
40
         }
40
         break;
41
         break;
41
     }
42
     }
43
+    case SET_CONFIG: {
44
+        const state = getState();
45
+        const { videoQuality = {} } = state['features/base/config'];
46
+
47
+        if (videoQuality.persist) {
48
+            dispatch(
49
+                setPreferredVideoQuality(
50
+                    state['features/video-quality-persistent-storage'].persistedPrefferedVideoQuality));
51
+        }
52
+
53
+        break;
54
+    }
42
     }
55
     }
43
 
56
 
44
     return result;
57
     return result;

+ 30
- 9
react/features/video-quality/reducer.js Просмотреть файл

1
 import { SET_CONFIG } from '../base/config';
1
 import { SET_CONFIG } from '../base/config';
2
-import { ReducerRegistry, set } from '../base/redux';
2
+import { PersistenceRegistry, ReducerRegistry, set } from '../base/redux';
3
 
3
 
4
 import { SET_MAX_RECEIVER_VIDEO_QUALITY, SET_PREFERRED_VIDEO_QUALITY } from './actionTypes';
4
 import { SET_MAX_RECEIVER_VIDEO_QUALITY, SET_PREFERRED_VIDEO_QUALITY } from './actionTypes';
5
 import { VIDEO_QUALITY_LEVELS } from './constants';
5
 import { VIDEO_QUALITY_LEVELS } from './constants';
6
 import { validateMinHeightForQualityLvl } from './functions';
6
 import { validateMinHeightForQualityLvl } from './functions';
7
 import logger from './logger';
7
 import logger from './logger';
8
 
8
 
9
-const STORE_NAME = 'features/video-quality';
10
-
11
 const DEFAULT_STATE = {
9
 const DEFAULT_STATE = {
12
     maxReceiverVideoQuality: VIDEO_QUALITY_LEVELS.HIGH,
10
     maxReceiverVideoQuality: VIDEO_QUALITY_LEVELS.HIGH,
13
     minHeightForQualityLvl: new Map(),
11
     minHeightForQualityLvl: new Map(),
17
 DEFAULT_STATE.minHeightForQualityLvl.set(360, VIDEO_QUALITY_LEVELS.STANDARD);
15
 DEFAULT_STATE.minHeightForQualityLvl.set(360, VIDEO_QUALITY_LEVELS.STANDARD);
18
 DEFAULT_STATE.minHeightForQualityLvl.set(720, VIDEO_QUALITY_LEVELS.HIGH);
16
 DEFAULT_STATE.minHeightForQualityLvl.set(720, VIDEO_QUALITY_LEVELS.HIGH);
19
 
17
 
20
-ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
18
+
19
+// When the persisted state is initialized the current state (for example the deafault state) is erased.
20
+// In order to workaround this issue we need additional state for the persisted properties.
21
+PersistenceRegistry.register('features/video-quality-persistent-storage');
22
+
23
+ReducerRegistry.register('features/video-quality-persistent-storage', (state = {}, action) => {
24
+    switch (action.type) {
25
+    case SET_PREFERRED_VIDEO_QUALITY: {
26
+        const { preferredVideoQuality } = action;
27
+
28
+        return {
29
+            ...state,
30
+            persistedPrefferedVideoQuality: preferredVideoQuality
31
+        };
32
+    }
33
+    }
34
+
35
+    return state;
36
+});
37
+
38
+ReducerRegistry.register('features/video-quality', (state = DEFAULT_STATE, action) => {
21
     switch (action.type) {
39
     switch (action.type) {
22
     case SET_CONFIG:
40
     case SET_CONFIG:
23
         return _setConfig(state, action);
41
         return _setConfig(state, action);
26
             state,
44
             state,
27
             'maxReceiverVideoQuality',
45
             'maxReceiverVideoQuality',
28
             action.maxReceiverVideoQuality);
46
             action.maxReceiverVideoQuality);
29
-    case SET_PREFERRED_VIDEO_QUALITY:
30
-        return set(
31
-            state,
32
-            'preferredVideoQuality',
33
-            action.preferredVideoQuality);
47
+    case SET_PREFERRED_VIDEO_QUALITY: {
48
+        const { preferredVideoQuality } = action;
49
+
50
+        return {
51
+            ...state,
52
+            preferredVideoQuality
53
+        };
54
+    }
34
     }
55
     }
35
 
56
 
36
     return state;
57
     return state;

Загрузка…
Отмена
Сохранить