You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Settings.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import {generateUsername} from '../util/UsernameGenerator';
  2. import UIUtil from '../UI/util/UIUtil';
  3. let email = '';
  4. let displayName = '';
  5. let userId;
  6. let language = null;
  7. let cameraDeviceId = '';
  8. let micDeviceId = '';
  9. let welcomePageDisabled = false;
  10. function supportsLocalStorage() {
  11. try {
  12. return 'localStorage' in window && window.localStorage !== null;
  13. } catch (e) {
  14. console.log("localstorage is not supported");
  15. return false;
  16. }
  17. }
  18. function generateUniqueId() {
  19. function _p8() {
  20. return (Math.random().toString(16) + "000000000").substr(2, 8);
  21. }
  22. return _p8() + _p8() + _p8() + _p8();
  23. }
  24. if (supportsLocalStorage()) {
  25. if (!window.localStorage.jitsiMeetId) {
  26. window.localStorage.jitsiMeetId = generateUniqueId();
  27. console.log("generated id", window.localStorage.jitsiMeetId);
  28. }
  29. userId = window.localStorage.jitsiMeetId || '';
  30. email = window.localStorage.email || '';
  31. displayName = UIUtil.unescapeHtml(window.localStorage.displayname || '');
  32. language = window.localStorage.language;
  33. cameraDeviceId = window.localStorage.cameraDeviceId || '';
  34. micDeviceId = window.localStorage.micDeviceId || '';
  35. welcomePageDisabled = JSON.parse(
  36. window.localStorage.welcomePageDisabled || false
  37. );
  38. } else {
  39. console.log("local storage is not supported");
  40. userId = generateUniqueId();
  41. }
  42. export default {
  43. /**
  44. * Sets the local user display name and saves it to local storage
  45. *
  46. * @param {string} newDisplayName unescaped display name for the local user
  47. */
  48. setDisplayName (newDisplayName) {
  49. displayName = newDisplayName;
  50. window.localStorage.displayname = UIUtil.escapeHtml(displayName);
  51. },
  52. /**
  53. * Returns the escaped display name currently used by the user
  54. * @returns {string} currently valid user display name.
  55. */
  56. getDisplayName: function () {
  57. return displayName;
  58. },
  59. /**
  60. * Returns id of the user.
  61. * @returns {string} user id
  62. */
  63. getUserId () {
  64. return userId;
  65. },
  66. setEmail: function (newEmail) {
  67. email = newEmail;
  68. window.localStorage.email = newEmail;
  69. return email;
  70. },
  71. getEmail: function () {
  72. return email;
  73. },
  74. getSettings: function () {
  75. return {
  76. email: email,
  77. displayName: displayName,
  78. uid: userId,
  79. language: language
  80. };
  81. },
  82. getLanguage () {
  83. return language;
  84. },
  85. setLanguage: function (lang) {
  86. language = lang;
  87. window.localStorage.language = lang;
  88. },
  89. /**
  90. * Get device id of the camera which is currently in use.
  91. * Empty string stands for default device.
  92. * @returns {String}
  93. */
  94. getCameraDeviceId: function () {
  95. return cameraDeviceId;
  96. },
  97. /**
  98. * Set device id of the camera which is currently in use.
  99. * Empty string stands for default device.
  100. * @param {string} newId new camera device id
  101. */
  102. setCameraDeviceId: function (newId = '') {
  103. cameraDeviceId = newId;
  104. window.localStorage.cameraDeviceId = newId;
  105. },
  106. /**
  107. * Get device id of the microphone which is currently in use.
  108. * Empty string stands for default device.
  109. * @returns {String}
  110. */
  111. getMicDeviceId: function () {
  112. return micDeviceId;
  113. },
  114. /**
  115. * Set device id of the microphone which is currently in use.
  116. * Empty string stands for default device.
  117. * @param {string} newId new microphone device id
  118. */
  119. setMicDeviceId: function (newId = '') {
  120. micDeviceId = newId;
  121. window.localStorage.micDeviceId = newId;
  122. },
  123. /**
  124. * Check if welcome page is enabled or not.
  125. * @returns {boolean}
  126. */
  127. isWelcomePageEnabled () {
  128. return !welcomePageDisabled;
  129. },
  130. /**
  131. * Enable or disable welcome page.
  132. * @param {boolean} enabled if welcome page should be enabled or not
  133. */
  134. setWelcomePageEnabled (enabled) {
  135. welcomePageDisabled = !enabled;
  136. window.localStorage.welcomePageDisabled = welcomePageDisabled;
  137. }
  138. };