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 3.9KB

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