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

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 audioOutputDeviceId = '';
  8. let welcomePageDisabled = false;
  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. displayName = UIUtil.unescapeHtml(window.localStorage.displayname || '');
  30. language = window.localStorage.language;
  31. cameraDeviceId = window.localStorage.cameraDeviceId || '';
  32. micDeviceId = window.localStorage.micDeviceId || '';
  33. welcomePageDisabled = JSON.parse(
  34. window.localStorage.welcomePageDisabled || false
  35. );
  36. } else {
  37. console.log("local storage is not supported");
  38. }
  39. export default {
  40. /**
  41. * Sets the local user display name and saves it to local storage
  42. *
  43. * @param {string} newDisplayName unescaped display name for the local user
  44. */
  45. setDisplayName (newDisplayName) {
  46. displayName = newDisplayName;
  47. window.localStorage.displayname = UIUtil.escapeHtml(displayName);
  48. },
  49. /**
  50. * Returns the escaped display name currently used by the user
  51. * @returns {string} currently valid user display name.
  52. */
  53. getDisplayName: function () {
  54. return displayName;
  55. },
  56. /**
  57. * Sets new email for local user and saves it to the local storage.
  58. * @param {string} newEmail new email for the local user
  59. */
  60. setEmail: function (newEmail) {
  61. email = newEmail;
  62. window.localStorage.email = UIUtil.escapeHtml(newEmail);
  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. * Get device id of the audio output device which is currently in use.
  114. * Empty string stands for default device.
  115. * @returns {String}
  116. */
  117. getAudioOutputDeviceId: function () {
  118. return audioOutputDeviceId;
  119. },
  120. /**
  121. * Set device id of the audio output device which is currently in use.
  122. * Empty string stands for default device.
  123. * @param {string} newId new audio output device id
  124. */
  125. setAudioOutputDeviceId: function (newId = '') {
  126. audioOutputDeviceId = newId;
  127. window.localStorage.audioOutputDeviceId = newId;
  128. },
  129. /**
  130. * Check if welcome page is enabled or not.
  131. * @returns {boolean}
  132. */
  133. isWelcomePageEnabled () {
  134. return !welcomePageDisabled;
  135. },
  136. /**
  137. * Enable or disable welcome page.
  138. * @param {boolean} enabled if welcome page should be enabled or not
  139. */
  140. setWelcomePageEnabled (enabled) {
  141. welcomePageDisabled = !enabled;
  142. window.localStorage.welcomePageDisabled = welcomePageDisabled;
  143. }
  144. };