2016-05-06 14:31:23 +00:00
|
|
|
/* global JitsiMeetJS */
|
2017-10-12 23:02:29 +00:00
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
2016-11-11 15:00:54 +00:00
|
|
|
|
2016-02-12 12:48:57 +00:00
|
|
|
import UIUtil from '../UI/util/UIUtil';
|
2016-10-27 18:19:11 +00:00
|
|
|
import jitsiLocalStorage from '../util/JitsiLocalStorage';
|
2017-02-28 23:12:02 +00:00
|
|
|
import { randomHexString } from '../../react/features/base/util';
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2016-10-27 18:19:11 +00:00
|
|
|
let avatarUrl = '';
|
2016-08-31 16:24:51 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
let email = UIUtil.unescapeHtml(jitsiLocalStorage.getItem('email') || '');
|
|
|
|
let avatarId = UIUtil.unescapeHtml(jitsiLocalStorage.getItem('avatarId') || '');
|
|
|
|
|
2016-10-27 18:19:11 +00:00
|
|
|
if (!avatarId) {
|
|
|
|
// if there is no avatar id, we generate a unique one and use it forever
|
2017-02-28 23:12:02 +00:00
|
|
|
avatarId = randomHexString(32);
|
2017-10-12 23:02:29 +00:00
|
|
|
jitsiLocalStorage.setItem('avatarId', avatarId);
|
2016-10-27 18:19:11 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
let localFlipX = JSON.parse(jitsiLocalStorage.getItem('localFlipX') || true);
|
2016-10-27 18:19:11 +00:00
|
|
|
let displayName = UIUtil.unescapeHtml(
|
2017-10-12 23:02:29 +00:00
|
|
|
jitsiLocalStorage.getItem('displayname') || '');
|
|
|
|
let cameraDeviceId = jitsiLocalStorage.getItem('cameraDeviceId') || '';
|
|
|
|
let micDeviceId = jitsiLocalStorage.getItem('micDeviceId') || '';
|
2016-10-27 18:19:11 +00:00
|
|
|
let welcomePageDisabled = JSON.parse(
|
2017-10-12 23:02:29 +00:00
|
|
|
jitsiLocalStorage.getItem('welcomePageDisabled') || false);
|
2016-10-27 18:19:11 +00:00
|
|
|
|
|
|
|
// Currently audio output device change is supported only in Chrome and
|
|
|
|
// default output always has 'default' device ID
|
2017-10-12 23:02:29 +00:00
|
|
|
const audioOutputDeviceId = jitsiLocalStorage.getItem('audioOutputDeviceId')
|
2016-10-27 18:19:11 +00:00
|
|
|
|| 'default';
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
if (audioOutputDeviceId
|
|
|
|
!== JitsiMeetJS.mediaDevices.getAudioOutputDevice()) {
|
2016-10-27 18:19:11 +00:00
|
|
|
JitsiMeetJS.mediaDevices.setAudioOutputDevice(audioOutputDeviceId)
|
2017-10-12 23:02:29 +00:00
|
|
|
.catch(ex => {
|
|
|
|
logger.warn('Failed to set audio output device from local '
|
|
|
|
+ 'storage. Default audio output device will be used'
|
|
|
|
+ 'instead.', ex);
|
2016-10-27 18:19:11 +00:00
|
|
|
});
|
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
|
|
|
|
*
|
2016-02-12 12:48:57 +00:00
|
|
|
* @param {string} newDisplayName unescaped display name for the local user
|
2016-08-30 19:10:20 +00:00
|
|
|
* @param {boolean} disableLocalStore disables local store the display name
|
2015-10-04 21:13:28 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
setDisplayName(newDisplayName, disableLocalStore) {
|
2015-01-07 14:54:03 +00:00
|
|
|
displayName = newDisplayName;
|
2016-08-30 19:10:20 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
if (!disableLocalStore) {
|
|
|
|
jitsiLocalStorage.setItem('displayname',
|
2016-10-27 18:19:11 +00:00
|
|
|
UIUtil.escapeHtml(displayName));
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
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.
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getDisplayName() {
|
2015-10-04 21:13:28 +00:00
|
|
|
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-08-30 19:10:20 +00:00
|
|
|
* @param {boolean} disableLocalStore disables local store the email
|
2016-02-12 12:48:57 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
setEmail(newEmail, disableLocalStore) {
|
2015-01-07 14:54:03 +00:00
|
|
|
email = newEmail;
|
2016-08-30 19:10:20 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
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
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getEmail() {
|
2015-12-02 15:24:57 +00:00
|
|
|
return email;
|
|
|
|
},
|
|
|
|
|
2016-08-31 16:24:51 +00:00
|
|
|
/**
|
|
|
|
* Returns avatar id of the local user.
|
|
|
|
* @returns {string} avatar id
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getAvatarId() {
|
2016-08-31 16:24:51 +00:00
|
|
|
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
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
setAvatarUrl(newAvatarUrl) {
|
2016-06-13 21:11:44 +00:00
|
|
|
avatarUrl = newAvatarUrl;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns avatarUrl address of the local user.
|
|
|
|
* @returns {string} avatarUrl
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getAvatarUrl() {
|
2016-06-13 21:11:44 +00:00
|
|
|
return avatarUrl;
|
|
|
|
},
|
|
|
|
|
2016-05-07 01:50:37 +00:00
|
|
|
/**
|
|
|
|
* Sets new flipX state of local video and saves it to the local storage.
|
|
|
|
* @param {string} val flipX state of local video
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
setLocalFlipX(val) {
|
2016-05-07 01:50:37 +00:00
|
|
|
localFlipX = val;
|
2017-10-12 23:02:29 +00:00
|
|
|
jitsiLocalStorage.setItem('localFlipX', val);
|
2016-05-07 01:50:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns flipX state of local video.
|
|
|
|
* @returns {string} flipX
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getLocalFlipX() {
|
2016-05-07 01:50:37 +00:00
|
|
|
return localFlipX;
|
|
|
|
},
|
|
|
|
|
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}
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getCameraDeviceId() {
|
2016-02-09 10:19:43 +00:00
|
|
|
return cameraDeviceId;
|
|
|
|
},
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-02-09 10:19:43 +00:00
|
|
|
/**
|
|
|
|
* Set device id of the camera which is currently in use.
|
|
|
|
* Empty string stands for default device.
|
|
|
|
* @param {string} newId new camera device id
|
2016-09-07 21:48:57 +00:00
|
|
|
* @param {boolean} whether we need to store the value
|
2016-02-09 10:19:43 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
setCameraDeviceId(newId, store) {
|
2016-02-09 10:19:43 +00:00
|
|
|
cameraDeviceId = newId;
|
2017-10-12 23:02:29 +00:00
|
|
|
if (store) {
|
|
|
|
jitsiLocalStorage.setItem('cameraDeviceId', newId);
|
|
|
|
}
|
2016-02-09 10:19:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get device id of the microphone which is currently in use.
|
|
|
|
* Empty string stands for default device.
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getMicDeviceId() {
|
2016-02-09 10:19:43 +00:00
|
|
|
return micDeviceId;
|
|
|
|
},
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-02-09 10:19:43 +00:00
|
|
|
/**
|
|
|
|
* Set device id of the microphone which is currently in use.
|
|
|
|
* Empty string stands for default device.
|
|
|
|
* @param {string} newId new microphone device id
|
2016-09-07 21:48:57 +00:00
|
|
|
* @param {boolean} whether we need to store the value
|
2016-02-09 10:19:43 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
setMicDeviceId(newId, store) {
|
2016-02-09 10:19:43 +00:00
|
|
|
micDeviceId = newId;
|
2017-10-12 23:02:29 +00:00
|
|
|
if (store) {
|
|
|
|
jitsiLocalStorage.setItem('micDeviceId', newId);
|
|
|
|
}
|
2016-02-25 13:52:15 +00:00
|
|
|
},
|
|
|
|
|
2016-05-05 14:34:15 +00:00
|
|
|
/**
|
|
|
|
* Get device id of the audio output device which is currently in use.
|
|
|
|
* Empty string stands for default device.
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
getAudioOutputDeviceId() {
|
2016-05-11 13:59:27 +00:00
|
|
|
return JitsiMeetJS.mediaDevices.getAudioOutputDevice();
|
2016-05-05 14:34:15 +00:00
|
|
|
},
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-05-05 14:34:15 +00:00
|
|
|
/**
|
|
|
|
* Set device id of the audio output device which is currently in use.
|
|
|
|
* Empty string stands for default device.
|
2016-05-17 15:58:25 +00:00
|
|
|
* @param {string} newId='default' - new audio output device id
|
2016-05-06 14:31:23 +00:00
|
|
|
* @returns {Promise}
|
2016-05-05 14:34:15 +00:00
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
setAudioOutputDeviceId(newId = 'default') {
|
2016-05-11 13:59:27 +00:00
|
|
|
return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
|
2016-10-27 18:19:11 +00:00
|
|
|
.then(() =>
|
2017-10-12 23:02:29 +00:00
|
|
|
jitsiLocalStorage.setItem('audioOutputDeviceId', newId));
|
2016-05-05 14:34:15 +00:00
|
|
|
},
|
|
|
|
|
2016-02-25 13:52:15 +00:00
|
|
|
/**
|
|
|
|
* Check if welcome page is enabled or not.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
isWelcomePageEnabled() {
|
2016-02-25 13:52:15 +00:00
|
|
|
return !welcomePageDisabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable or disable welcome page.
|
|
|
|
* @param {boolean} enabled if welcome page should be enabled or not
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
setWelcomePageEnabled(enabled) {
|
2016-02-25 13:52:15 +00:00
|
|
|
welcomePageDisabled = !enabled;
|
2017-10-12 23:02:29 +00:00
|
|
|
jitsiLocalStorage.setItem('welcomePageDisabled', welcomePageDisabled);
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
|
|
|
};
|