Browse Source

Merge pull request #1080 from jitsi/dont_show_again

Implement dont show again util
j8
Дамян Минков 8 years ago
parent
commit
1036768b2a

+ 3
- 2
connection.js View File

@@ -1,5 +1,6 @@
1 1
 /* global APP, JitsiMeetJS, config */
2 2
 import AuthHandler from './modules/UI/authentication/AuthHandler';
3
+import jitsiLocalStorage from './modules/util/JitsiLocalStorage';
3 4
 
4 5
 const ConnectionEvents = JitsiMeetJS.events.connection;
5 6
 const ConnectionErrors = JitsiMeetJS.errors.connection;
@@ -107,9 +108,9 @@ function connect(id, password, roomName) {
107 108
 export function openConnection({id, password, retry, roomName}) {
108 109
 
109 110
     let usernameOverride
110
-        = window.localStorage.getItem("xmpp_username_override");
111
+        = jitsiLocalStorage.getItem("xmpp_username_override");
111 112
     let passwordOverride
112
-        = window.localStorage.getItem("xmpp_password_override");
113
+        = jitsiLocalStorage.getItem("xmpp_password_override");
113 114
 
114 115
     if (usernameOverride && usernameOverride.length > 0) {
115 116
         id = usernameOverride;

+ 10
- 30
modules/UI/UI.js View File

@@ -1214,7 +1214,11 @@ UI.showExtensionExternalInstallationDialog = function (url) {
1214 1214
  * @param {JitsiTrackError} cameraError
1215 1215
  */
1216 1216
 UI.showDeviceErrorDialog = function (micError, cameraError) {
1217
-    let localStoragePropName = "doNotShowErrorAgain";
1217
+    let dontShowAgain = {
1218
+        id: "doNotShowWarningAgain",
1219
+        localStorageKey: "doNotShowErrorAgain",
1220
+        textKey: "dialog.doNotShowWarningAgain"
1221
+    };
1218 1222
     let isMicJitsiTrackErrorAndHasName = micError && micError.name &&
1219 1223
         micError instanceof JitsiMeetJS.errorTypes.JitsiTrackError;
1220 1224
     let isCameraJitsiTrackErrorAndHasName = cameraError && cameraError.name &&
@@ -1231,17 +1235,11 @@ UI.showDeviceErrorDialog = function (micError, cameraError) {
1231 1235
     }
1232 1236
 
1233 1237
     if (micError) {
1234
-        localStoragePropName += "-mic-" + micError.name;
1238
+        dontShowAgain.localStorageKey += "-mic-" + micError.name;
1235 1239
     }
1236 1240
 
1237 1241
     if (cameraError) {
1238
-        localStoragePropName += "-camera-" + cameraError.name;
1239
-    }
1240
-
1241
-    if (showDoNotShowWarning) {
1242
-        if (window.localStorage[localStoragePropName] === "true") {
1243
-            return;
1244
-        }
1242
+        dontShowAgain.localStorageKey += "-camera-" + cameraError.name;
1245 1243
     }
1246 1244
 
1247 1245
     let cameraJitsiTrackErrorMsg = cameraError
@@ -1266,12 +1264,6 @@ UI.showDeviceErrorDialog = function (micError, cameraError) {
1266 1264
         micError.message
1267 1265
             ? `<div>${micError.message}</div>`
1268 1266
             : ``;
1269
-    let doNotShowWarningAgainSection = showDoNotShowWarning
1270
-        ? `<label>
1271
-            <input type='checkbox' id='doNotShowWarningAgain'>
1272
-            <span data-i18n='dialog.doNotShowWarningAgain'></span>
1273
-           </label>`
1274
-        : ``;
1275 1267
     let message = '';
1276 1268
 
1277 1269
     if (micError) {
@@ -1290,8 +1282,6 @@ UI.showDeviceErrorDialog = function (micError, cameraError) {
1290 1282
             ${additionalCameraErrorMsg}`;
1291 1283
     }
1292 1284
 
1293
-    message = `${message}${doNotShowWarningAgainSection}`;
1294
-
1295 1285
     // To make sure we don't have multiple error dialogs open at the same time,
1296 1286
     // we will just close the previous one if we are going to show a new one.
1297 1287
     deviceErrorDialog && deviceErrorDialog.close();
@@ -1301,24 +1291,14 @@ UI.showDeviceErrorDialog = function (micError, cameraError) {
1301 1291
         message,
1302 1292
         false,
1303 1293
         {Ok: true},
1304
-        function () {
1305
-            let form  = $.prompt.getPrompt();
1306
-
1307
-            if (form) {
1308
-                let input = form.find("#doNotShowWarningAgain");
1309
-
1310
-                if (input.length) {
1311
-                    window.localStorage[localStoragePropName] =
1312
-                        input.prop("checked");
1313
-                }
1314
-            }
1315
-        },
1294
+        function () {},
1316 1295
         null,
1317 1296
         function () {
1318 1297
             // Reset dialog reference to null to avoid memory leaks when
1319 1298
             // user closed the dialog manually.
1320 1299
             deviceErrorDialog = null;
1321
-        }
1300
+        },
1301
+        showDoNotShowWarning ? dontShowAgain : undefined
1322 1302
     );
1323 1303
 
1324 1304
     function getTitleKey() {

+ 134
- 10
modules/UI/util/MessageHandler.js View File

@@ -1,6 +1,7 @@
1 1
 /* global $, APP, toastr, Impromptu */
2 2
 
3 3
 import UIUtil from './UIUtil';
4
+import jitsiLocalStorage from '../../util/JitsiLocalStorage';
4 5
 
5 6
 /**
6 7
  * Flag for enable/disable of the notifications.
@@ -20,6 +21,91 @@ let popupEnabled = true;
20 21
  */
21 22
 let twoButtonDialog = null;
22 23
 
24
+/**
25
+ * Generates html for dont show again checkbox.
26
+ * @param {object} options options
27
+ * @param {string} options.id the id of the checkbox.
28
+ * @param {string} options.textKey the key for the text displayed next to
29
+ * checkbox
30
+ * @param {boolean} options.checked if true the checkbox is foing to be checked
31
+ * by default.
32
+ * @returns {string}
33
+ */
34
+function generateDontShowCheckbox(options) {
35
+    if(!isDontShowAgainEnabled(options)) {
36
+        return "";
37
+    }
38
+
39
+    let checked
40
+        = (options.checked === true) ? "checked" : "";
41
+    return `<br />
42
+        <label>
43
+            <input type='checkbox' ${checked} id='${options.id}' />
44
+            <span data-i18n='${options.textKey}'></span>
45
+        </label>`;
46
+}
47
+
48
+/**
49
+ * Checks whether the dont show again checkbox was checked before.
50
+ * @param {object} options - options for dont show again checkbox.
51
+ * @param {string} options.id the id of the checkbox.
52
+ * @param {string} options.localStorageKey the key for the local storage. if
53
+ * not provided options.id will be used.
54
+ * @returns {boolean} true if the dialog mustn't be displayed and
55
+ * false otherwise.
56
+ */
57
+function dontShowTheDialog(options) {
58
+    if(isDontShowAgainEnabled(options)) {
59
+        if(jitsiLocalStorage.getItem(options.localStorageKey || options.id)
60
+            === "true") {
61
+            return true;
62
+        }
63
+    }
64
+    return false;
65
+}
66
+
67
+/**
68
+ * Wraps the submit function to process the dont show again status and store
69
+ * it.
70
+ * @param {object} options - options for dont show again checkbox.
71
+ * @param {string} options.id the id of the checkbox.
72
+ * @param {Array} options.buttonValues The button values that will trigger
73
+ * storing he checkbox value
74
+ * @param {string} options.localStorageKey the key for the local storage. if
75
+ * not provided options.id will be used.
76
+ * @param {Function} submitFunction the submit function to be wrapped
77
+ * @returns {Function} wrapped function
78
+ */
79
+function dontShowAgainSubmitFunctionWrapper(options, submitFunction) {
80
+    if(isDontShowAgainEnabled(options)) {
81
+        return (...args) => {
82
+            console.debug(args, options.buttonValues);
83
+            //args[1] is the value associated with the pressed button
84
+            if(!options.buttonValues || options.buttonValues.length === 0
85
+                || options.buttonValues.indexOf(args[1]) !== -1 ) {
86
+                let checkbox = $(`#${options.id}`);
87
+                if (checkbox.length) {
88
+                    jitsiLocalStorage.setItem(
89
+                        options.localStorageKey || options.id,
90
+                        checkbox.prop("checked"));
91
+                }
92
+            }
93
+            submitFunction(...args);
94
+        };
95
+    } else {
96
+        return submitFunction;
97
+    }
98
+}
99
+
100
+/**
101
+ * Check whether dont show again checkbox is enabled or not.
102
+ * @param {object} options - options for dont show again checkbox.
103
+ * @returns {boolean} true if enabled and false if not.
104
+ */
105
+function isDontShowAgainEnabled(options) {
106
+    return typeof options === "object";
107
+}
108
+
23 109
 var messageHandler = {
24 110
     OK: "dialog.OK",
25 111
     CANCEL: "dialog.Cancel",
@@ -72,6 +158,16 @@ var messageHandler = {
72 158
      *        the dialog is opened
73 159
      * @param defaultButton index of default button which will be activated when
74 160
      *        the user press 'enter'. Indexed from 0.
161
+     * @param {object} dontShowAgain - options for dont show again checkbox.
162
+     * @param {string} dontShowAgain.id the id of the checkbox.
163
+     * @param {string} dontShowAgain.textKey the key for the text displayed
164
+     * next to checkbox
165
+     * @param {boolean} dontShowAgain.checked if true the checkbox is foing to
166
+     * be checked
167
+     * @param {Array} dontShowAgain.buttonValues The button values that will
168
+     * trigger storing the checkbox value
169
+     * @param {string} dontShowAgain.localStorageKey the key for the local
170
+     * storage. if not provided dontShowAgain.id will be used.
75 171
      * @return the prompt that was created, or null
76 172
      */
77 173
     openTwoButtonDialog: function(options) {
@@ -87,12 +183,20 @@ var messageHandler = {
87 183
             size,
88 184
             defaultButton,
89 185
             wrapperClass,
90
-            classes
186
+            classes,
187
+            dontShowAgain
91 188
         } = options;
92 189
 
93 190
         if (!popupEnabled || twoButtonDialog)
94 191
             return null;
95 192
 
193
+        if(dontShowTheDialog(dontShowAgain)) {
194
+            // Maybe we should pass some parameters here? I'm not sure
195
+            // and currently we don't need any parameters.
196
+            submitFunction();
197
+            return null;
198
+        }
199
+
96 200
         var buttons = [];
97 201
 
98 202
         var leftButton = leftButtonKey ?
@@ -108,6 +212,7 @@ var messageHandler = {
108 212
         if (msgKey) {
109 213
             message = APP.translation.generateTranslationHTML(msgKey);
110 214
         }
215
+        message += generateDontShowCheckbox(dontShowAgain);
111 216
         classes = classes || this._getDialogClasses(size);
112 217
         if (wrapperClass) {
113 218
             classes.prompt += ` ${wrapperClass}`;
@@ -122,13 +227,13 @@ var messageHandler = {
122 227
             loaded: loadedFunction,
123 228
             promptspeed: 0,
124 229
             classes,
125
-            submit: function (e, v, m, f) {
126
-                twoButtonDialog = null;
127
-                if (v){
128
-                    if (submitFunction)
230
+            submit: dontShowAgainSubmitFunctionWrapper(dontShowAgain,
231
+                function (e, v, m, f) {
232
+                    twoButtonDialog = null;
233
+                    if (v && submitFunction) {
129 234
                         submitFunction(e, v, m, f);
130
-                }
131
-            },
235
+                    }
236
+                }),
132 237
             close: function (e, v, m, f) {
133 238
                 twoButtonDialog = null;
134 239
                 if (closeFunction) {
@@ -155,12 +260,29 @@ var messageHandler = {
155 260
      * @param loadedFunction function to be called after the prompt is fully
156 261
      *        loaded
157 262
      * @param closeFunction function to be called on dialog close
263
+     * @param {object} dontShowAgain - options for dont show again checkbox.
264
+     * @param {string} dontShowAgain.id the id of the checkbox.
265
+     * @param {string} dontShowAgain.textKey the key for the text displayed
266
+     * next to checkbox
267
+     * @param {boolean} dontShowAgain.checked if true the checkbox is foing to
268
+     * be checked
269
+     * @param {Array} dontShowAgain.buttonValues The button values that will
270
+     * trigger storing the checkbox value
271
+     * @param {string} dontShowAgain.localStorageKey the key for the local
272
+     * storage. if not provided dontShowAgain.id will be used.
158 273
      */
159 274
     openDialog: function (titleKey, msgString, persistent, buttons,
160
-                              submitFunction, loadedFunction, closeFunction) {
275
+        submitFunction, loadedFunction, closeFunction, dontShowAgain) {
161 276
         if (!popupEnabled)
162 277
             return;
163 278
 
279
+        if(dontShowTheDialog(dontShowAgain)) {
280
+            // Maybe we should pass some parameters here? I'm not sure
281
+            // and currently we don't need any parameters.
282
+            submitFunction();
283
+            return;
284
+        }
285
+
164 286
         let args = {
165 287
             title: this._getFormattedTitleString(titleKey),
166 288
             persistent: persistent,
@@ -168,7 +290,8 @@ var messageHandler = {
168 290
             defaultButton: 1,
169 291
             promptspeed: 0,
170 292
             loaded: loadedFunction,
171
-            submit: submitFunction,
293
+            submit: dontShowAgainSubmitFunctionWrapper(
294
+                dontShowAgain, submitFunction),
172 295
             close: closeFunction,
173 296
             classes: this._getDialogClasses()
174 297
         };
@@ -177,7 +300,8 @@ var messageHandler = {
177 300
             args.closeText = '';
178 301
         }
179 302
 
180
-        let dialog = new Impromptu(msgString, args);
303
+        let dialog = new Impromptu(
304
+            msgString + generateDontShowCheckbox(dontShowAgain), args);
181 305
         APP.translation.translateElement(dialog.getPrompt());
182 306
         return dialog;
183 307
     },

+ 8
- 29
modules/UI/videolayout/RemoteVideo.js View File

@@ -652,39 +652,18 @@ RemoteVideo.createContainer = function (spanId) {
652 652
  * participant.
653 653
  */
654 654
 RemoteVideo.showMuteParticipantDialog = function () {
655
-    //FIXME: don't show again checkbox is implemented very dirty. we should add
656
-    // this functionality to MessageHandler class.
657
-    if (window.localStorage
658
-        && window.localStorage.getItem(
659
-            "dontShowMuteParticipantDialog") === "true") {
660
-        return Promise.resolve(MUTED_DIALOG_BUTTON_VALUES.muted);
661
-    }
662
-    let msgString =
663
-        `<div data-i18n="dialog.muteParticipantBody"></div>
664
-        <br />
665
-        <label>
666
-            <input type='checkbox' checked id='doNotShowMessageAgain' />
667
-            <span data-i18n='dialog.doNotShowMessageAgain'></span>
668
-        </label>`;
669 655
     return new Promise(resolve => {
670 656
         APP.UI.messageHandler.openTwoButtonDialog({
671 657
             titleKey : "dialog.muteParticipantTitle",
672
-            msgString,
673
-            leftButtonKey: 'dialog.muteParticipantButton',
674
-            submitFunction: () => {
675
-                if(window.localStorage) {
676
-                    let form  = $.prompt.getPrompt();
677
-                    if (form) {
678
-                        let input = form.find("#doNotShowMessageAgain");
679
-                        if (input.length) {
680
-                            window.localStorage.setItem(
681
-                                "dontShowMuteParticipantDialog",
682
-                                input.prop("checked"));
683
-                        }
684
-                    }
685
-                }
686
-                resolve(MUTED_DIALOG_BUTTON_VALUES.muted);
658
+            msgString: "<div data-i18n='dialog.muteParticipantBody'></div>",
659
+            leftButtonKey: "dialog.muteParticipantButton",
660
+            dontShowAgain: {
661
+                id: "dontShowMuteParticipantDialog",
662
+                textKey: "dialog.doNotShowMessageAgain",
663
+                checked: true,
664
+                buttonValues: [true]
687 665
             },
666
+            submitFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.muted),
688 667
             closeFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.cancel)
689 668
         });
690 669
     });

+ 46
- 66
modules/settings/Settings.js View File

@@ -1,26 +1,6 @@
1 1
 /* global JitsiMeetJS */
2
-
3 2
 import UIUtil from '../UI/util/UIUtil';
4
-
5
-let email = '';
6
-let avatarId = '';
7
-let displayName = '';
8
-let language = null;
9
-let cameraDeviceId = '';
10
-let micDeviceId = '';
11
-let welcomePageDisabled = false;
12
-let localFlipX = null;
13
-let avatarUrl = '';
14
-
15
-function supportsLocalStorage() {
16
-    try {
17
-        return 'localStorage' in window && window.localStorage !== null;
18
-    } catch (e) {
19
-        console.log("localstorage is not supported");
20
-        return false;
21
-    }
22
-}
23
-
3
+import jitsiLocalStorage from '../util/JitsiLocalStorage';
24 4
 
25 5
 function generateUniqueId() {
26 6
     function _p8() {
@@ -29,45 +9,43 @@ function generateUniqueId() {
29 9
     return _p8() + _p8() + _p8() + _p8();
30 10
 }
31 11
 
32
-if (supportsLocalStorage()) {
33
-    if (!window.localStorage.jitsiMeetId) {
34
-        window.localStorage.jitsiMeetId = generateUniqueId();
35
-        console.log("generated id", window.localStorage.jitsiMeetId);
36
-    }
12
+if (!jitsiLocalStorage.getItem("jitsiMeetId")) {
13
+    jitsiLocalStorage.setItem("jitsiMeetId",generateUniqueId());
14
+    console.log("generated id", jitsiLocalStorage.getItem("jitsiMeetId"));
15
+}
37 16
 
38
-    email = UIUtil.unescapeHtml(window.localStorage.email || '');
39
-    avatarId = UIUtil.unescapeHtml(window.localStorage.avatarId || '');
40
-    if (!avatarId) {
41
-        // if there is no avatar id, we generate a unique one and use it forever
42
-        avatarId = generateUniqueId();
43
-        window.localStorage.avatarId = avatarId;
44
-    }
17
+let avatarUrl = '';
45 18
 
46
-    localFlipX = JSON.parse(window.localStorage.localFlipX || true);
47
-    displayName = UIUtil.unescapeHtml(window.localStorage.displayname || '');
48
-    language = window.localStorage.language;
49
-    cameraDeviceId = window.localStorage.cameraDeviceId || '';
50
-    micDeviceId = window.localStorage.micDeviceId || '';
51
-    welcomePageDisabled = JSON.parse(
52
-        window.localStorage.welcomePageDisabled || false
53
-    );
54
-
55
-    // Currently audio output device change is supported only in Chrome and
56
-    // default output always has 'default' device ID
57
-    var audioOutputDeviceId = window.localStorage.audioOutputDeviceId
58
-        || 'default';
59
-
60
-    if (audioOutputDeviceId !==
61
-        JitsiMeetJS.mediaDevices.getAudioOutputDevice()) {
62
-        JitsiMeetJS.mediaDevices.setAudioOutputDevice(audioOutputDeviceId)
63
-            .catch((ex) => {
64
-                console.warn('Failed to set audio output device from local ' +
65
-                    'storage. Default audio output device will be used' +
66
-                    'instead.', ex);
67
-            });
68
-    }
69
-} else {
70
-    console.log("local storage is not supported");
19
+let email = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("email") || '');
20
+let avatarId = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("avatarId") || '');
21
+if (!avatarId) {
22
+    // if there is no avatar id, we generate a unique one and use it forever
23
+    avatarId = generateUniqueId();
24
+    jitsiLocalStorage.setItem("avatarId", avatarId);
25
+}
26
+
27
+let localFlipX = JSON.parse(jitsiLocalStorage.getItem("localFlipX") || true);
28
+let displayName = UIUtil.unescapeHtml(
29
+    jitsiLocalStorage.getItem("displayname") || '');
30
+let language = jitsiLocalStorage.getItem("language");
31
+let cameraDeviceId = jitsiLocalStorage.getItem("cameraDeviceId") || '';
32
+let micDeviceId = jitsiLocalStorage.getItem("micDeviceId") || '';
33
+let welcomePageDisabled = JSON.parse(
34
+    jitsiLocalStorage.getItem("welcomePageDisabled") || false);
35
+
36
+// Currently audio output device change is supported only in Chrome and
37
+// default output always has 'default' device ID
38
+let audioOutputDeviceId = jitsiLocalStorage.getItem("audioOutputDeviceId")
39
+    || 'default';
40
+
41
+if (audioOutputDeviceId !==
42
+    JitsiMeetJS.mediaDevices.getAudioOutputDevice()) {
43
+    JitsiMeetJS.mediaDevices.setAudioOutputDevice(audioOutputDeviceId)
44
+        .catch((ex) => {
45
+            console.warn('Failed to set audio output device from local ' +
46
+                'storage. Default audio output device will be used' +
47
+                'instead.', ex);
48
+        });
71 49
 }
72 50
 
73 51
 export default {
@@ -82,7 +60,8 @@ export default {
82 60
         displayName = newDisplayName;
83 61
 
84 62
         if (!disableLocalStore)
85
-            window.localStorage.displayname = UIUtil.escapeHtml(displayName);
63
+            jitsiLocalStorage.setItem("displayname",
64
+                UIUtil.escapeHtml(displayName));
86 65
     },
87 66
 
88 67
     /**
@@ -102,7 +81,7 @@ export default {
102 81
         email = newEmail;
103 82
 
104 83
         if (!disableLocalStore)
105
-            window.localStorage.email = UIUtil.escapeHtml(newEmail);
84
+            jitsiLocalStorage.setItem("email", UIUtil.escapeHtml(newEmail));
106 85
     },
107 86
 
108 87
     /**
@@ -142,7 +121,7 @@ export default {
142 121
     },
143 122
     setLanguage: function (lang) {
144 123
         language = lang;
145
-        window.localStorage.language = lang;
124
+        jitsiLocalStorage.setItem("language", lang);
146 125
     },
147 126
 
148 127
     /**
@@ -151,7 +130,7 @@ export default {
151 130
      */
152 131
     setLocalFlipX: function (val) {
153 132
         localFlipX = val;
154
-        window.localStorage.localFlipX = val;
133
+        jitsiLocalStorage.setItem("localFlipX", val);
155 134
     },
156 135
 
157 136
     /**
@@ -179,7 +158,7 @@ export default {
179 158
     setCameraDeviceId: function (newId, store) {
180 159
         cameraDeviceId = newId;
181 160
         if (store)
182
-            window.localStorage.cameraDeviceId = newId;
161
+            jitsiLocalStorage.setItem("cameraDeviceId", newId);
183 162
     },
184 163
 
185 164
     /**
@@ -199,7 +178,7 @@ export default {
199 178
     setMicDeviceId: function (newId, store) {
200 179
         micDeviceId = newId;
201 180
         if (store)
202
-            window.localStorage.micDeviceId = newId;
181
+            jitsiLocalStorage.setItem("micDeviceId", newId);
203 182
     },
204 183
 
205 184
     /**
@@ -218,7 +197,8 @@ export default {
218 197
      */
219 198
     setAudioOutputDeviceId: function (newId = 'default') {
220 199
         return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
221
-            .then(() => window.localStorage.audioOutputDeviceId = newId);
200
+            .then(() =>
201
+                jitsiLocalStorage.setItem("audioOutputDeviceId", newId));
222 202
     },
223 203
 
224 204
     /**
@@ -235,6 +215,6 @@ export default {
235 215
      */
236 216
     setWelcomePageEnabled (enabled) {
237 217
         welcomePageDisabled = !enabled;
238
-        window.localStorage.welcomePageDisabled = welcomePageDisabled;
218
+        jitsiLocalStorage.setItem("welcomePageDisabled", welcomePageDisabled);
239 219
     }
240 220
 };

+ 64
- 0
modules/util/JitsiLocalStorage.js View File

@@ -0,0 +1,64 @@
1
+/**
2
+ * Dummy implementation of Storage interface with empty methods.
3
+ */
4
+class DummyLocalStorage {
5
+    /**
6
+     * Empty function
7
+     */
8
+    getItem() { }
9
+
10
+    /**
11
+     * Empty function
12
+     */
13
+    setItem() { }
14
+
15
+    /**
16
+     * Empty function
17
+     */
18
+    removeItem() { }
19
+}
20
+
21
+/**
22
+ * Wrapper class for browser's local storage object.
23
+ */
24
+class JitsiLocalStorage extends DummyLocalStorage {
25
+    /**
26
+     * @constructor
27
+     * @param {Storage} storage browser's local storage object.
28
+     */
29
+    constructor(storage) {
30
+        super();
31
+        this.storage = storage || new DummyLocalStorage();
32
+    }
33
+
34
+    /**
35
+     * Returns that passed key's value.
36
+     * @param {string} keyName the name of the key you want to retrieve
37
+     * the value of.
38
+     * @returns {String|null} the value of the key. If the key does not exist,
39
+     * null is returned.
40
+     */
41
+    getItem(keyName) {
42
+        return this.storage.getItem(keyName);
43
+    }
44
+
45
+    /**
46
+     * Adds a key to the storage, or update key's value if it already exists.
47
+     * @param {string} keyName the name of the key you want to create/update.
48
+     * @param {string} keyValue the value you want to give the key you are
49
+     * creating/updating.
50
+     */
51
+    setItem(keyName, keyValue) {
52
+        return this.storage.setItem(keyName, keyValue);
53
+    }
54
+
55
+    /**
56
+     * Remove a key from the storage.
57
+     * @param {string} keyName the name of the key you want to remove.
58
+     */
59
+    removeItem(keyName) {
60
+        return this.storage.removeItem(keyName);
61
+    }
62
+}
63
+
64
+export default new JitsiLocalStorage(window.localStorage);

Loading…
Cancel
Save