Browse Source

feat(video-quality): persist.

j8
Hristo Terezov 4 years ago
parent
commit
25839b18d2

+ 4
- 2
react/features/video-quality/components/OverflowMenuVideoQualityItem.web.js View File

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

+ 6
- 3
react/features/video-quality/components/VideoQualitySlider.web.js View File

@@ -316,10 +316,13 @@ class VideoQualitySlider extends Component<Props> {
316 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 328
     _onSliderChange: () => void;

+ 20
- 0
react/features/video-quality/functions.js View File

@@ -2,6 +2,26 @@
2 2
 
3 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 27
  * Selects {@code VIDEO_QUALITY_LEVELS} for the given {@link availableHeight} and threshold to quality mapping.

+ 13
- 0
react/features/video-quality/middleware.js View File

@@ -4,6 +4,7 @@ import {
4 4
     CONFERENCE_JOINED,
5 5
     DATA_CHANNEL_OPENED
6 6
 } from '../base/conference';
7
+import { SET_CONFIG } from '../base/config';
7 8
 import { getParticipantCount } from '../base/participants';
8 9
 import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
9 10
 import { shouldDisplayTileView } from '../video-layout';
@@ -39,6 +40,18 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
39 40
         }
40 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 57
     return result;

+ 30
- 9
react/features/video-quality/reducer.js View File

@@ -1,13 +1,11 @@
1 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 4
 import { SET_MAX_RECEIVER_VIDEO_QUALITY, SET_PREFERRED_VIDEO_QUALITY } from './actionTypes';
5 5
 import { VIDEO_QUALITY_LEVELS } from './constants';
6 6
 import { validateMinHeightForQualityLvl } from './functions';
7 7
 import logger from './logger';
8 8
 
9
-const STORE_NAME = 'features/video-quality';
10
-
11 9
 const DEFAULT_STATE = {
12 10
     maxReceiverVideoQuality: VIDEO_QUALITY_LEVELS.HIGH,
13 11
     minHeightForQualityLvl: new Map(),
@@ -17,7 +15,27 @@ const DEFAULT_STATE = {
17 15
 DEFAULT_STATE.minHeightForQualityLvl.set(360, VIDEO_QUALITY_LEVELS.STANDARD);
18 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 39
     switch (action.type) {
22 40
     case SET_CONFIG:
23 41
         return _setConfig(state, action);
@@ -26,11 +44,14 @@ ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
26 44
             state,
27 45
             'maxReceiverVideoQuality',
28 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 57
     return state;

Loading…
Cancel
Save