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.4KB

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