jiti-meet/modules/settings/Settings.js

131 lines
3.4 KiB
JavaScript
Raw Normal View History

2015-12-29 12:41:43 +00:00
import {generateUsername} from '../util/UsernameGenerator';
2015-11-04 13:08:16 +00:00
let email = '';
let displayName = '';
let userId;
let language = null;
let cameraDeviceId = '';
let micDeviceId = '';
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-01-07 14:54:03 +00:00
userId = window.localStorage.jitsiMeetId || '';
email = window.localStorage.email || '';
displayName = window.localStorage.displayname || '';
language = window.localStorage.language;
cameraDeviceId = window.localStorage.cameraDeviceId || '';
micDeviceId = window.localStorage.micDeviceId || '';
2015-01-07 14:54:03 +00:00
} else {
console.log("local storage is not supported");
userId = generateUniqueId();
}
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
*
* @param newDisplayName the new display name for the local user
* @returns {string} the display name we just set
*/
2015-01-07 14:54:03 +00:00
setDisplayName: function (newDisplayName) {
2015-12-01 12:53:01 +00:00
if (displayName === newDisplayName) {
return displayName;
}
2015-01-07 14:54:03 +00:00
displayName = newDisplayName;
window.localStorage.displayname = displayName;
return displayName;
},
2015-10-04 21:13:28 +00:00
/**
* Returns the currently used by the user
* @returns {string} currently valid user display name.
*/
getDisplayName: function () {
return displayName;
},
setEmail: function (newEmail) {
2015-01-07 14:54:03 +00:00
email = newEmail;
window.localStorage.email = newEmail;
return email;
},
2015-10-04 21:13:28 +00:00
2015-12-02 15:24:57 +00:00
getEmail: function () {
return email;
},
2015-01-07 14:54:03 +00:00
getSettings: function () {
return {
email: email,
displayName: displayName,
uid: userId,
language: language
2015-01-07 14:54:03 +00:00
};
},
2015-12-29 12:41:43 +00:00
getLanguage () {
return language;
},
setLanguage: function (lang) {
language = lang;
window.localStorage.language = lang;
},
/**
* 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;
2015-01-07 14:54:03 +00:00
}
};