123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- /* global JitsiMeetJS */
-
- import UIUtil from '../UI/util/UIUtil';
-
- let email = '';
- let displayName = '';
- let language = null;
- let cameraDeviceId = '';
- let micDeviceId = '';
- let welcomePageDisabled = false;
- let localFlipX = null;
- let avatarUrl = '';
-
- function supportsLocalStorage() {
- try {
- return 'localStorage' in window && window.localStorage !== null;
- } catch (e) {
- console.log("localstorage is not supported");
- return false;
- }
- }
-
-
- function generateUniqueId() {
- function _p8() {
- return (Math.random().toString(16) + "000000000").substr(2, 8);
- }
- return _p8() + _p8() + _p8() + _p8();
- }
-
- if (supportsLocalStorage()) {
- if (!window.localStorage.jitsiMeetId) {
- window.localStorage.jitsiMeetId = generateUniqueId();
- console.log("generated id", window.localStorage.jitsiMeetId);
- }
-
- email = UIUtil.unescapeHtml(window.localStorage.email || '');
- avatarUrl = UIUtil.unescapeHtml(window.localStorage.avatarUrl || '');
- localFlipX = JSON.parse(window.localStorage.localFlipX || true);
- displayName = UIUtil.unescapeHtml(window.localStorage.displayname || '');
- language = window.localStorage.language;
- cameraDeviceId = window.localStorage.cameraDeviceId || '';
- micDeviceId = window.localStorage.micDeviceId || '';
- welcomePageDisabled = JSON.parse(
- window.localStorage.welcomePageDisabled || false
- );
-
- // Currently audio output device change is supported only in Chrome and
- // default output always has 'default' device ID
- var audioOutputDeviceId = window.localStorage.audioOutputDeviceId
- || 'default';
-
- if (audioOutputDeviceId !==
- JitsiMeetJS.mediaDevices.getAudioOutputDevice()) {
- JitsiMeetJS.mediaDevices.setAudioOutputDevice(audioOutputDeviceId)
- .catch((ex) => {
- console.warn('Failed to set audio output device from local ' +
- 'storage. Default audio output device will be used' +
- 'instead.', ex);
- });
- }
- } else {
- console.log("local storage is not supported");
- }
-
- export default {
-
- /**
- * Sets the local user display name and saves it to local storage
- *
- * @param {string} newDisplayName unescaped display name for the local user
- */
- setDisplayName (newDisplayName) {
- displayName = newDisplayName;
- window.localStorage.displayname = UIUtil.escapeHtml(displayName);
- },
-
- /**
- * Returns the escaped display name currently used by the user
- * @returns {string} currently valid user display name.
- */
- getDisplayName: function () {
- return displayName;
- },
-
- /**
- * Sets new email for local user and saves it to the local storage.
- * @param {string} newEmail new email for the local user
- */
- setEmail: function (newEmail) {
- email = newEmail;
- window.localStorage.email = UIUtil.escapeHtml(newEmail);
- },
-
- /**
- * Returns email address of the local user.
- * @returns {string} email
- */
- getEmail: function () {
- return email;
- },
-
- /**
- * 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;
- window.localStorage.avatarUrl = UIUtil.escapeHtml(newAvatarUrl);
- },
-
- /**
- * Returns avatarUrl address of the local user.
- * @returns {string} avatarUrl
- */
- getAvatarUrl: function () {
- return avatarUrl;
- },
-
-
- getLanguage () {
- return language;
- },
- setLanguage: function (lang) {
- language = lang;
- window.localStorage.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;
- window.localStorage.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
- */
- 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;
- },
-
- /**
- * 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(() => window.localStorage.audioOutputDeviceId = newId);
- },
-
- /**
- * 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;
- }
- };
|