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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 = 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 = newEmail;
  62. return email;
  63. },
  64. /**
  65. * Returns email address of the local user.
  66. * @returns {string} email
  67. */
  68. getEmail: function () {
  69. return email;
  70. },
  71. getLanguage () {
  72. return language;
  73. },
  74. setLanguage: function (lang) {
  75. language = lang;
  76. window.localStorage.language = lang;
  77. },
  78. /**
  79. * Get device id of the camera which is currently in use.
  80. * Empty string stands for default device.
  81. * @returns {String}
  82. */
  83. getCameraDeviceId: function () {
  84. return cameraDeviceId;
  85. },
  86. /**
  87. * Set device id of the camera which is currently in use.
  88. * Empty string stands for default device.
  89. * @param {string} newId new camera device id
  90. */
  91. setCameraDeviceId: function (newId = '') {
  92. cameraDeviceId = newId;
  93. window.localStorage.cameraDeviceId = newId;
  94. },
  95. /**
  96. * Get device id of the microphone which is currently in use.
  97. * Empty string stands for default device.
  98. * @returns {String}
  99. */
  100. getMicDeviceId: function () {
  101. return micDeviceId;
  102. },
  103. /**
  104. * Set device id of the microphone which is currently in use.
  105. * Empty string stands for default device.
  106. * @param {string} newId new microphone device id
  107. */
  108. setMicDeviceId: function (newId = '') {
  109. micDeviceId = newId;
  110. window.localStorage.micDeviceId = newId;
  111. },
  112. /**
  113. * Check if welcome page is enabled or not.
  114. * @returns {boolean}
  115. */
  116. isWelcomePageEnabled () {
  117. return !welcomePageDisabled;
  118. },
  119. /**
  120. * Enable or disable welcome page.
  121. * @param {boolean} enabled if welcome page should be enabled or not
  122. */
  123. setWelcomePageEnabled (enabled) {
  124. welcomePageDisabled = !enabled;
  125. window.localStorage.welcomePageDisabled = welcomePageDisabled;
  126. }
  127. };