|
|
@@ -1,4 +1,5 @@
|
|
1
|
1
|
// @flow
|
|
|
2
|
+
|
|
2
|
3
|
import Logger from 'jitsi-meet-logger';
|
|
3
|
4
|
import md5 from 'js-md5';
|
|
4
|
5
|
|
|
|
@@ -15,25 +16,26 @@ const PERSISTED_STATE_NAME = 'jitsi-state';
|
|
15
|
16
|
declare type PersistencyConfigMap = { [name: string]: Object };
|
|
16
|
17
|
|
|
17
|
18
|
/**
|
|
18
|
|
- * A registry to allow features to register their redux store
|
|
19
|
|
- * subtree to be persisted and also handles the persistency calls too.
|
|
|
19
|
+ * A registry to allow features to register their redux store subtree to be
|
|
|
20
|
+ * persisted and also handles the persistency calls too.
|
|
20
|
21
|
*/
|
|
21
|
22
|
class PersistencyRegistry {
|
|
22
|
23
|
_checksum: string;
|
|
|
24
|
+
|
|
23
|
25
|
_elements: PersistencyConfigMap;
|
|
24
|
26
|
|
|
25
|
27
|
/**
|
|
26
|
|
- * Initiates the PersistencyRegistry.
|
|
|
28
|
+ * Initializes a new {@ code PersistencyRegistry} instance.
|
|
27
|
29
|
*/
|
|
28
|
30
|
constructor() {
|
|
29
|
31
|
this._elements = {};
|
|
30
|
32
|
}
|
|
31
|
33
|
|
|
32
|
34
|
/**
|
|
33
|
|
- * Returns the persisted redux state. This function takes
|
|
34
|
|
- * the PersistencyRegistry._elements into account as we may have
|
|
35
|
|
- * persisted something in the past that we don't want to retreive anymore.
|
|
36
|
|
- * The next {@link #persistState} will remove those values.
|
|
|
35
|
+ * Returns the persisted redux state. This function takes the
|
|
|
36
|
+ * {@link #_elements} into account as we may have persisted something in the
|
|
|
37
|
+ * past that we don't want to retreive anymore. The next
|
|
|
38
|
+ * {@link #persistState} will remove those values.
|
|
37
|
39
|
*
|
|
38
|
40
|
* @returns {Object}
|
|
39
|
41
|
*/
|
|
|
@@ -46,8 +48,9 @@ class PersistencyRegistry {
|
|
46
|
48
|
persistedState = JSON.parse(persistedState);
|
|
47
|
49
|
} catch (error) {
|
|
48
|
50
|
logger.error(
|
|
49
|
|
- 'Error parsing persisted state', persistedState, error
|
|
50
|
|
- );
|
|
|
51
|
+ 'Error parsing persisted state',
|
|
|
52
|
+ persistedState,
|
|
|
53
|
+ error);
|
|
51
|
54
|
persistedState = {};
|
|
52
|
55
|
}
|
|
53
|
56
|
|
|
|
@@ -56,14 +59,14 @@ class PersistencyRegistry {
|
|
56
|
59
|
}
|
|
57
|
60
|
|
|
58
|
61
|
this._checksum = this._calculateChecksum(filteredPersistedState);
|
|
59
|
|
- logger.info('Redux state rehydrated as', filteredPersistedState);
|
|
|
62
|
+ logger.info('redux state rehydrated as', filteredPersistedState);
|
|
60
|
63
|
|
|
61
|
64
|
return filteredPersistedState;
|
|
62
|
65
|
}
|
|
63
|
66
|
|
|
64
|
67
|
/**
|
|
65
|
|
- * Initiates a persist operation, but its execution will depend on
|
|
66
|
|
- * the current checksums (checks changes).
|
|
|
68
|
+ * Initiates a persist operation, but its execution will depend on the
|
|
|
69
|
+ * current checksums (checks changes).
|
|
67
|
70
|
*
|
|
68
|
71
|
* @param {Object} state - The redux state.
|
|
69
|
72
|
* @returns {void}
|
|
|
@@ -76,14 +79,13 @@ class PersistencyRegistry {
|
|
76
|
79
|
try {
|
|
77
|
80
|
window.localStorage.setItem(
|
|
78
|
81
|
PERSISTED_STATE_NAME,
|
|
79
|
|
- JSON.stringify(filteredState)
|
|
80
|
|
- );
|
|
|
82
|
+ JSON.stringify(filteredState));
|
|
81
|
83
|
logger.info(
|
|
82
|
|
- `Redux state persisted. ${this._checksum} -> ${newCheckSum}`
|
|
83
|
|
- );
|
|
|
84
|
+ `redux state persisted. ${this._checksum} -> ${
|
|
|
85
|
+ newCheckSum}`);
|
|
84
|
86
|
this._checksum = newCheckSum;
|
|
85
|
87
|
} catch (error) {
|
|
86
|
|
- logger.error('Error persisting Redux state', error);
|
|
|
88
|
+ logger.error('Error persisting redux state', error);
|
|
87
|
89
|
}
|
|
88
|
90
|
}
|
|
89
|
91
|
}
|
|
|
@@ -103,7 +105,7 @@ class PersistencyRegistry {
|
|
103
|
105
|
* Calculates the checksum of the current or the new values of the state.
|
|
104
|
106
|
*
|
|
105
|
107
|
* @private
|
|
106
|
|
- * @param {Object} filteredState - The filtered/persisted Redux state.
|
|
|
108
|
+ * @param {Object} filteredState - The filtered/persisted redux state.
|
|
107
|
109
|
* @returns {string}
|
|
108
|
110
|
*/
|
|
109
|
111
|
_calculateChecksum(filteredState: Object) {
|
|
|
@@ -111,16 +113,17 @@ class PersistencyRegistry {
|
|
111
|
113
|
return md5.hex(JSON.stringify(filteredState) || '');
|
|
112
|
114
|
} catch (error) {
|
|
113
|
115
|
logger.error(
|
|
114
|
|
- 'Error calculating checksum for state', filteredState, error
|
|
115
|
|
- );
|
|
|
116
|
+ 'Error calculating checksum for state',
|
|
|
117
|
+ filteredState,
|
|
|
118
|
+ error);
|
|
116
|
119
|
|
|
117
|
120
|
return '';
|
|
118
|
121
|
}
|
|
119
|
122
|
}
|
|
120
|
123
|
|
|
121
|
124
|
/**
|
|
122
|
|
- * Prepares a filtered state from the actual or the
|
|
123
|
|
- * persisted Redux state, based on this registry.
|
|
|
125
|
+ * Prepares a filtered state from the actual or the persisted redux state,
|
|
|
126
|
+ * based on this registry.
|
|
124
|
127
|
*
|
|
125
|
128
|
* @private
|
|
126
|
129
|
* @param {Object} state - The actual or persisted redux state.
|
|
|
@@ -131,10 +134,10 @@ class PersistencyRegistry {
|
|
131
|
134
|
|
|
132
|
135
|
for (const name of Object.keys(this._elements)) {
|
|
133
|
136
|
if (state[name]) {
|
|
134
|
|
- filteredState[name] = this._getFilteredSubtree(
|
|
135
|
|
- state[name],
|
|
136
|
|
- this._elements[name]
|
|
137
|
|
- );
|
|
|
137
|
+ filteredState[name]
|
|
|
138
|
+ = this._getFilteredSubtree(
|
|
|
139
|
+ state[name],
|
|
|
140
|
+ this._elements[name]);
|
|
138
|
141
|
}
|
|
139
|
142
|
}
|
|
140
|
143
|
|
|
|
@@ -142,8 +145,8 @@ class PersistencyRegistry {
|
|
142
|
145
|
}
|
|
143
|
146
|
|
|
144
|
147
|
/**
|
|
145
|
|
- * Prepares a filtered subtree based on the config for
|
|
146
|
|
- * persisting or for retreival.
|
|
|
148
|
+ * Prepares a filtered subtree based on the config for persisting or for
|
|
|
149
|
+ * retrieval.
|
|
147
|
150
|
*
|
|
148
|
151
|
* @private
|
|
149
|
152
|
* @param {Object} subtree - The redux state subtree.
|
|
|
@@ -155,8 +158,7 @@ class PersistencyRegistry {
|
|
155
|
158
|
|
|
156
|
159
|
for (const persistedKey of Object.keys(subtree)) {
|
|
157
|
160
|
if (subtreeConfig[persistedKey]) {
|
|
158
|
|
- filteredSubtree[persistedKey]
|
|
159
|
|
- = subtree[persistedKey];
|
|
|
161
|
+ filteredSubtree[persistedKey] = subtree[persistedKey];
|
|
160
|
162
|
}
|
|
161
|
163
|
}
|
|
162
|
164
|
|