2016-02-12 12:48:57 +00:00
|
|
|
import UIUtil from '../UI/util/UIUtil';
|
2015-11-04 13:08:16 +00:00
|
|
|
|
2016-02-09 10:19:43 +00:00
|
|
|
let email = '';
|
|
|
|
let displayName = '';
|
|
|
|
let language = null;
|
|
|
|
let cameraDeviceId = '';
|
|
|
|
let micDeviceId = '';
|
2016-02-25 13:52:15 +00:00
|
|
|
let welcomePageDisabled = false;
|
2015-01-07 14:54:03 +00:00
|
|
|
|
|
|
|
function supportsLocalStorage() {
|
|
|
|
try {
|
|
|
|
return 'localStorage' in window && window.localStorage !== null;
|
|
|
|
} catch (e) {
|
|
|
|
console.log("localstorage is not supported");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function generateUniqueId() {
|
|
|
|
function _p8() {
|
2015-02-13 09:38:37 +00:00
|
|
|
return (Math.random().toString(16) + "000000000").substr(2, 8);
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
|
|
|
return _p8() + _p8() + _p8() + _p8();
|
|
|
|
}
|
|
|
|
|
2015-02-13 09:38:37 +00:00
|
|
|
if (supportsLocalStorage()) {
|
|
|
|
if (!window.localStorage.jitsiMeetId) {
|
2015-01-07 14:54:03 +00:00
|
|
|
window.localStorage.jitsiMeetId = generateUniqueId();
|
|
|
|
console.log("generated id", window.localStorage.jitsiMeetId);
|
|
|
|
}
|
2015-11-06 11:19:45 +00:00
|
|
|
|
2016-03-02 15:39:39 +00:00
|
|
|
email = UIUtil.unescapeHtml(window.localStorage.email || '');
|
2016-02-12 12:48:57 +00:00
|
|
|
displayName = UIUtil.unescapeHtml(window.localStorage.displayname || '');
|
2015-02-24 10:49:46 +00:00
|
|
|
language = window.localStorage.language;
|
2016-02-09 10:19:43 +00:00
|
|
|
cameraDeviceId = window.localStorage.cameraDeviceId || '';
|
|
|
|
micDeviceId = window.localStorage.micDeviceId || '';
|
2016-02-25 13:52:15 +00:00
|
|
|
welcomePageDisabled = JSON.parse(
|
|
|
|
window.localStorage.welcomePageDisabled || false
|
|
|
|
);
|
2015-01-07 14:54:03 +00:00
|
|
|
} else {
|
|
|
|
console.log("local storage is not supported");
|
|
|
|
}
|
|
|
|
|
2015-12-29 12:41:43 +00:00
|
|
|
export default {
|
2015-10-04 21:13:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the local user display name and saves it to local storage
|
|
|
|
*
|
2016-02-12 12:48:57 +00:00
|
|
|
* @param {string} newDisplayName unescaped display name for the local user
|
2015-10-04 21:13:28 +00:00
|
|
|
*/
|
2016-02-12 12:48:57 +00:00
|
|
|
setDisplayName (newDisplayName) {
|
2015-01-07 14:54:03 +00:00
|
|
|
displayName = newDisplayName;
|
2016-02-12 12:48:57 +00:00
|
|
|
window.localStorage.displayname = UIUtil.escapeHtml(displayName);
|
2015-01-07 14:54:03 +00:00
|
|
|
},
|
2015-10-04 21:13:28 +00:00
|
|
|
|
|
|
|
/**
|
2016-02-12 12:48:57 +00:00
|
|
|
* Returns the escaped display name currently used by the user
|
2015-10-04 21:13:28 +00:00
|
|
|
* @returns {string} currently valid user display name.
|
|
|
|
*/
|
|
|
|
getDisplayName: function () {
|
|
|
|
return displayName;
|
|
|
|
},
|
|
|
|
|
2016-02-12 12:48:57 +00:00
|
|
|
/**
|
2016-02-24 16:03:16 +00:00
|
|
|
* Sets new email for local user and saves it to the local storage.
|
|
|
|
* @param {string} newEmail new email for the local user
|
2016-02-12 12:48:57 +00:00
|
|
|
*/
|
2015-07-28 18:22:11 +00:00
|
|
|
setEmail: function (newEmail) {
|
2015-01-07 14:54:03 +00:00
|
|
|
email = newEmail;
|
2016-03-02 15:39:39 +00:00
|
|
|
window.localStorage.email = UIUtil.escapeHtml(newEmail);
|
2015-01-07 14:54:03 +00:00
|
|
|
},
|
2015-10-04 21:13:28 +00:00
|
|
|
|
2016-02-24 16:03:16 +00:00
|
|
|
/**
|
|
|
|
* Returns email address of the local user.
|
|
|
|
* @returns {string} email
|
|
|
|
*/
|
2015-12-02 15:24:57 +00:00
|
|
|
getEmail: function () {
|
|
|
|
return email;
|
|
|
|
},
|
|
|
|
|
2015-12-29 12:41:43 +00:00
|
|
|
getLanguage () {
|
|
|
|
return language;
|
|
|
|
},
|
2015-02-24 10:49:46 +00:00
|
|
|
setLanguage: function (lang) {
|
|
|
|
language = lang;
|
|
|
|
window.localStorage.language = lang;
|
2016-02-09 10:19:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get device id of the camera which is currently in use.
|
|
|
|
* Empty string stands for default device.
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
getCameraDeviceId: function () {
|
|
|
|
return cameraDeviceId;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Set device id of the camera which is currently in use.
|
|
|
|
* Empty string stands for default device.
|
|
|
|
* @param {string} newId new camera device id
|
|
|
|
*/
|
|
|
|
setCameraDeviceId: function (newId = '') {
|
|
|
|
cameraDeviceId = newId;
|
|
|
|
window.localStorage.cameraDeviceId = newId;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get device id of the microphone which is currently in use.
|
|
|
|
* Empty string stands for default device.
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
getMicDeviceId: function () {
|
|
|
|
return micDeviceId;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Set device id of the microphone which is currently in use.
|
|
|
|
* Empty string stands for default device.
|
|
|
|
* @param {string} newId new microphone device id
|
|
|
|
*/
|
|
|
|
setMicDeviceId: function (newId = '') {
|
|
|
|
micDeviceId = newId;
|
|
|
|
window.localStorage.micDeviceId = newId;
|
2016-02-25 13:52:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if welcome page is enabled or not.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
isWelcomePageEnabled () {
|
|
|
|
return !welcomePageDisabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable or disable welcome page.
|
|
|
|
* @param {boolean} enabled if welcome page should be enabled or not
|
|
|
|
*/
|
|
|
|
setWelcomePageEnabled (enabled) {
|
|
|
|
welcomePageDisabled = !enabled;
|
|
|
|
window.localStorage.welcomePageDisabled = welcomePageDisabled;
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
|
|
|
};
|