|
@@ -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;
|