Browse Source

Merge pull request #1080 from jitsi/dont_show_again

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

+ 3
- 2
connection.js View File

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

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

1214
  * @param {JitsiTrackError} cameraError
1214
  * @param {JitsiTrackError} cameraError
1215
  */
1215
  */
1216
 UI.showDeviceErrorDialog = function (micError, cameraError) {
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
     let isMicJitsiTrackErrorAndHasName = micError && micError.name &&
1222
     let isMicJitsiTrackErrorAndHasName = micError && micError.name &&
1219
         micError instanceof JitsiMeetJS.errorTypes.JitsiTrackError;
1223
         micError instanceof JitsiMeetJS.errorTypes.JitsiTrackError;
1220
     let isCameraJitsiTrackErrorAndHasName = cameraError && cameraError.name &&
1224
     let isCameraJitsiTrackErrorAndHasName = cameraError && cameraError.name &&
1231
     }
1235
     }
1232
 
1236
 
1233
     if (micError) {
1237
     if (micError) {
1234
-        localStoragePropName += "-mic-" + micError.name;
1238
+        dontShowAgain.localStorageKey += "-mic-" + micError.name;
1235
     }
1239
     }
1236
 
1240
 
1237
     if (cameraError) {
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
     let cameraJitsiTrackErrorMsg = cameraError
1245
     let cameraJitsiTrackErrorMsg = cameraError
1266
         micError.message
1264
         micError.message
1267
             ? `<div>${micError.message}</div>`
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
     let message = '';
1267
     let message = '';
1276
 
1268
 
1277
     if (micError) {
1269
     if (micError) {
1290
             ${additionalCameraErrorMsg}`;
1282
             ${additionalCameraErrorMsg}`;
1291
     }
1283
     }
1292
 
1284
 
1293
-    message = `${message}${doNotShowWarningAgainSection}`;
1294
-
1295
     // To make sure we don't have multiple error dialogs open at the same time,
1285
     // To make sure we don't have multiple error dialogs open at the same time,
1296
     // we will just close the previous one if we are going to show a new one.
1286
     // we will just close the previous one if we are going to show a new one.
1297
     deviceErrorDialog && deviceErrorDialog.close();
1287
     deviceErrorDialog && deviceErrorDialog.close();
1301
         message,
1291
         message,
1302
         false,
1292
         false,
1303
         {Ok: true},
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
         null,
1295
         null,
1317
         function () {
1296
         function () {
1318
             // Reset dialog reference to null to avoid memory leaks when
1297
             // Reset dialog reference to null to avoid memory leaks when
1319
             // user closed the dialog manually.
1298
             // user closed the dialog manually.
1320
             deviceErrorDialog = null;
1299
             deviceErrorDialog = null;
1321
-        }
1300
+        },
1301
+        showDoNotShowWarning ? dontShowAgain : undefined
1322
     );
1302
     );
1323
 
1303
 
1324
     function getTitleKey() {
1304
     function getTitleKey() {

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

1
 /* global $, APP, toastr, Impromptu */
1
 /* global $, APP, toastr, Impromptu */
2
 
2
 
3
 import UIUtil from './UIUtil';
3
 import UIUtil from './UIUtil';
4
+import jitsiLocalStorage from '../../util/JitsiLocalStorage';
4
 
5
 
5
 /**
6
 /**
6
  * Flag for enable/disable of the notifications.
7
  * Flag for enable/disable of the notifications.
20
  */
21
  */
21
 let twoButtonDialog = null;
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
 var messageHandler = {
109
 var messageHandler = {
24
     OK: "dialog.OK",
110
     OK: "dialog.OK",
25
     CANCEL: "dialog.Cancel",
111
     CANCEL: "dialog.Cancel",
72
      *        the dialog is opened
158
      *        the dialog is opened
73
      * @param defaultButton index of default button which will be activated when
159
      * @param defaultButton index of default button which will be activated when
74
      *        the user press 'enter'. Indexed from 0.
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
      * @return the prompt that was created, or null
171
      * @return the prompt that was created, or null
76
      */
172
      */
77
     openTwoButtonDialog: function(options) {
173
     openTwoButtonDialog: function(options) {
87
             size,
183
             size,
88
             defaultButton,
184
             defaultButton,
89
             wrapperClass,
185
             wrapperClass,
90
-            classes
186
+            classes,
187
+            dontShowAgain
91
         } = options;
188
         } = options;
92
 
189
 
93
         if (!popupEnabled || twoButtonDialog)
190
         if (!popupEnabled || twoButtonDialog)
94
             return null;
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
         var buttons = [];
200
         var buttons = [];
97
 
201
 
98
         var leftButton = leftButtonKey ?
202
         var leftButton = leftButtonKey ?
108
         if (msgKey) {
212
         if (msgKey) {
109
             message = APP.translation.generateTranslationHTML(msgKey);
213
             message = APP.translation.generateTranslationHTML(msgKey);
110
         }
214
         }
215
+        message += generateDontShowCheckbox(dontShowAgain);
111
         classes = classes || this._getDialogClasses(size);
216
         classes = classes || this._getDialogClasses(size);
112
         if (wrapperClass) {
217
         if (wrapperClass) {
113
             classes.prompt += ` ${wrapperClass}`;
218
             classes.prompt += ` ${wrapperClass}`;
122
             loaded: loadedFunction,
227
             loaded: loadedFunction,
123
             promptspeed: 0,
228
             promptspeed: 0,
124
             classes,
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
                         submitFunction(e, v, m, f);
234
                         submitFunction(e, v, m, f);
130
-                }
131
-            },
235
+                    }
236
+                }),
132
             close: function (e, v, m, f) {
237
             close: function (e, v, m, f) {
133
                 twoButtonDialog = null;
238
                 twoButtonDialog = null;
134
                 if (closeFunction) {
239
                 if (closeFunction) {
155
      * @param loadedFunction function to be called after the prompt is fully
260
      * @param loadedFunction function to be called after the prompt is fully
156
      *        loaded
261
      *        loaded
157
      * @param closeFunction function to be called on dialog close
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
     openDialog: function (titleKey, msgString, persistent, buttons,
274
     openDialog: function (titleKey, msgString, persistent, buttons,
160
-                              submitFunction, loadedFunction, closeFunction) {
275
+        submitFunction, loadedFunction, closeFunction, dontShowAgain) {
161
         if (!popupEnabled)
276
         if (!popupEnabled)
162
             return;
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
         let args = {
286
         let args = {
165
             title: this._getFormattedTitleString(titleKey),
287
             title: this._getFormattedTitleString(titleKey),
166
             persistent: persistent,
288
             persistent: persistent,
168
             defaultButton: 1,
290
             defaultButton: 1,
169
             promptspeed: 0,
291
             promptspeed: 0,
170
             loaded: loadedFunction,
292
             loaded: loadedFunction,
171
-            submit: submitFunction,
293
+            submit: dontShowAgainSubmitFunctionWrapper(
294
+                dontShowAgain, submitFunction),
172
             close: closeFunction,
295
             close: closeFunction,
173
             classes: this._getDialogClasses()
296
             classes: this._getDialogClasses()
174
         };
297
         };
177
             args.closeText = '';
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
         APP.translation.translateElement(dialog.getPrompt());
305
         APP.translation.translateElement(dialog.getPrompt());
182
         return dialog;
306
         return dialog;
183
     },
307
     },

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

652
  * participant.
652
  * participant.
653
  */
653
  */
654
 RemoteVideo.showMuteParticipantDialog = function () {
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
     return new Promise(resolve => {
655
     return new Promise(resolve => {
670
         APP.UI.messageHandler.openTwoButtonDialog({
656
         APP.UI.messageHandler.openTwoButtonDialog({
671
             titleKey : "dialog.muteParticipantTitle",
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
             closeFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.cancel)
667
             closeFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.cancel)
689
         });
668
         });
690
     });
669
     });

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

1
 /* global JitsiMeetJS */
1
 /* global JitsiMeetJS */
2
-
3
 import UIUtil from '../UI/util/UIUtil';
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
 function generateUniqueId() {
5
 function generateUniqueId() {
26
     function _p8() {
6
     function _p8() {
29
     return _p8() + _p8() + _p8() + _p8();
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
 export default {
51
 export default {
82
         displayName = newDisplayName;
60
         displayName = newDisplayName;
83
 
61
 
84
         if (!disableLocalStore)
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
         email = newEmail;
81
         email = newEmail;
103
 
82
 
104
         if (!disableLocalStore)
83
         if (!disableLocalStore)
105
-            window.localStorage.email = UIUtil.escapeHtml(newEmail);
84
+            jitsiLocalStorage.setItem("email", UIUtil.escapeHtml(newEmail));
106
     },
85
     },
107
 
86
 
108
     /**
87
     /**
142
     },
121
     },
143
     setLanguage: function (lang) {
122
     setLanguage: function (lang) {
144
         language = lang;
123
         language = lang;
145
-        window.localStorage.language = lang;
124
+        jitsiLocalStorage.setItem("language", lang);
146
     },
125
     },
147
 
126
 
148
     /**
127
     /**
151
      */
130
      */
152
     setLocalFlipX: function (val) {
131
     setLocalFlipX: function (val) {
153
         localFlipX = val;
132
         localFlipX = val;
154
-        window.localStorage.localFlipX = val;
133
+        jitsiLocalStorage.setItem("localFlipX", val);
155
     },
134
     },
156
 
135
 
157
     /**
136
     /**
179
     setCameraDeviceId: function (newId, store) {
158
     setCameraDeviceId: function (newId, store) {
180
         cameraDeviceId = newId;
159
         cameraDeviceId = newId;
181
         if (store)
160
         if (store)
182
-            window.localStorage.cameraDeviceId = newId;
161
+            jitsiLocalStorage.setItem("cameraDeviceId", newId);
183
     },
162
     },
184
 
163
 
185
     /**
164
     /**
199
     setMicDeviceId: function (newId, store) {
178
     setMicDeviceId: function (newId, store) {
200
         micDeviceId = newId;
179
         micDeviceId = newId;
201
         if (store)
180
         if (store)
202
-            window.localStorage.micDeviceId = newId;
181
+            jitsiLocalStorage.setItem("micDeviceId", newId);
203
     },
182
     },
204
 
183
 
205
     /**
184
     /**
218
      */
197
      */
219
     setAudioOutputDeviceId: function (newId = 'default') {
198
     setAudioOutputDeviceId: function (newId = 'default') {
220
         return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
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
      */
215
      */
236
     setWelcomePageEnabled (enabled) {
216
     setWelcomePageEnabled (enabled) {
237
         welcomePageDisabled = !enabled;
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

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