jiti-meet/modules/settings/Settings.js

218 lines
6.6 KiB
JavaScript
Raw Normal View History

/* global JitsiMeetJS */
2016-11-11 15:00:54 +00:00
const logger = require("jitsi-meet-logger").getLogger(__filename);
import UIUtil from '../UI/util/UIUtil';
import jitsiLocalStorage from '../util/JitsiLocalStorage';
2015-01-07 14:54:03 +00:00
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();
}
let avatarUrl = '';
2016-08-31 16:24:51 +00:00
let email = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("email") || '');
let avatarId = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("avatarId") || '');
if (!avatarId) {
// if there is no avatar id, we generate a unique one and use it forever
avatarId = generateUniqueId();
jitsiLocalStorage.setItem("avatarId", avatarId);
}
let localFlipX = JSON.parse(jitsiLocalStorage.getItem("localFlipX") || true);
let displayName = UIUtil.unescapeHtml(
jitsiLocalStorage.getItem("displayname") || '');
let language = jitsiLocalStorage.getItem("language");
let cameraDeviceId = jitsiLocalStorage.getItem("cameraDeviceId") || '';
let micDeviceId = jitsiLocalStorage.getItem("micDeviceId") || '';
let welcomePageDisabled = JSON.parse(
jitsiLocalStorage.getItem("welcomePageDisabled") || false);
// Currently audio output device change is supported only in Chrome and
// default output always has 'default' device ID
let audioOutputDeviceId = jitsiLocalStorage.getItem("audioOutputDeviceId")
|| 'default';
if (audioOutputDeviceId !==
JitsiMeetJS.mediaDevices.getAudioOutputDevice()) {
JitsiMeetJS.mediaDevices.setAudioOutputDevice(audioOutputDeviceId)
.catch((ex) => {
2016-11-11 15:00:54 +00:00
logger.warn('Failed to set audio output device from local ' +
'storage. Default audio output device will be used' +
'instead.', ex);
});
2015-01-07 14:54:03 +00:00
}
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 {string} newDisplayName unescaped display name for the local user
* @param {boolean} disableLocalStore disables local store the display name
2015-10-04 21:13:28 +00:00
*/
setDisplayName (newDisplayName, disableLocalStore) {
2015-01-07 14:54:03 +00:00
displayName = newDisplayName;
if (!disableLocalStore)
jitsiLocalStorage.setItem("displayname",
UIUtil.escapeHtml(displayName));
2015-01-07 14:54:03 +00:00
},
2015-10-04 21:13:28 +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-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
* @param {boolean} disableLocalStore disables local store the email
*/
setEmail: function (newEmail, disableLocalStore) {
2015-01-07 14:54:03 +00:00
email = newEmail;
if (!disableLocalStore)
jitsiLocalStorage.setItem("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;
},
2016-08-31 16:24:51 +00:00
/**
* Returns avatar id of the local user.
* @returns {string} avatar id
*/
getAvatarId: function () {
return avatarId;
},
2016-06-13 21:11:44 +00:00
/**
* Sets new avatarUrl for local user and saves it to the local storage.
* @param {string} newAvatarUrl new avatarUrl for the local user
*/
setAvatarUrl: function (newAvatarUrl) {
avatarUrl = newAvatarUrl;
},
/**
* Returns avatarUrl address of the local user.
* @returns {string} avatarUrl
*/
getAvatarUrl: function () {
return avatarUrl;
},
2015-12-29 12:41:43 +00:00
getLanguage () {
return language;
},
setLanguage: function (lang) {
language = lang;
jitsiLocalStorage.setItem("language", lang);
},
/**
* Sets new flipX state of local video and saves it to the local storage.
* @param {string} val flipX state of local video
*/
setLocalFlipX: function (val) {
localFlipX = val;
jitsiLocalStorage.setItem("localFlipX", val);
},
/**
* Returns flipX state of local video.
* @returns {string} flipX
*/
getLocalFlipX: function () {
return localFlipX;
},
/**
* 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
* @param {boolean} whether we need to store the value
*/
setCameraDeviceId: function (newId, store) {
cameraDeviceId = newId;
if (store)
jitsiLocalStorage.setItem("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
* @param {boolean} whether we need to store the value
*/
setMicDeviceId: function (newId, store) {
micDeviceId = newId;
if (store)
jitsiLocalStorage.setItem("micDeviceId", newId);
2016-02-25 13:52:15 +00:00
},
/**
* Get device id of the audio output device which is currently in use.
* Empty string stands for default device.
* @returns {String}
*/
getAudioOutputDeviceId: function () {
return JitsiMeetJS.mediaDevices.getAudioOutputDevice();
},
/**
* Set device id of the audio output device which is currently in use.
* Empty string stands for default device.
* @param {string} newId='default' - new audio output device id
* @returns {Promise}
*/
setAudioOutputDeviceId: function (newId = 'default') {
return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
.then(() =>
jitsiLocalStorage.setItem("audioOutputDeviceId", 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;
jitsiLocalStorage.setItem("welcomePageDisabled", welcomePageDisabled);
2015-01-07 14:54:03 +00:00
}
};