您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Settings.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* global JitsiMeetJS */
  2. import UIUtil from '../UI/util/UIUtil';
  3. let email = '';
  4. let displayName = '';
  5. let language = null;
  6. let cameraDeviceId = '';
  7. let micDeviceId = '';
  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. var audioOutputDeviceId = window.localStorage.audioOutputDeviceId;
  37. if (typeof audioOutputDeviceId !== 'undefined' &&
  38. audioOutputDeviceId !== JitsiMeetJS.getAudioOutputDevice()) {
  39. JitsiMeetJS.setAudioOutputDevice(
  40. window.localStorage.audioOutputDeviceId).catch((ex) => {
  41. console.error('failed to set audio output device from local ' +
  42. 'storage', ex);
  43. });
  44. }
  45. } else {
  46. console.log("local storage is not supported");
  47. }
  48. export default {
  49. /**
  50. * Sets the local user display name and saves it to local storage
  51. *
  52. * @param {string} newDisplayName unescaped display name for the local user
  53. */
  54. setDisplayName (newDisplayName) {
  55. displayName = newDisplayName;
  56. window.localStorage.displayname = UIUtil.escapeHtml(displayName);
  57. },
  58. /**
  59. * Returns the escaped display name currently used by the user
  60. * @returns {string} currently valid user display name.
  61. */
  62. getDisplayName: function () {
  63. return displayName;
  64. },
  65. /**
  66. * Sets new email for local user and saves it to the local storage.
  67. * @param {string} newEmail new email for the local user
  68. */
  69. setEmail: function (newEmail) {
  70. email = newEmail;
  71. window.localStorage.email = UIUtil.escapeHtml(newEmail);
  72. },
  73. /**
  74. * Returns email address of the local user.
  75. * @returns {string} email
  76. */
  77. getEmail: function () {
  78. return email;
  79. },
  80. getLanguage () {
  81. return language;
  82. },
  83. setLanguage: function (lang) {
  84. language = lang;
  85. window.localStorage.language = lang;
  86. },
  87. /**
  88. * Get device id of the camera which is currently in use.
  89. * Empty string stands for default device.
  90. * @returns {String}
  91. */
  92. getCameraDeviceId: function () {
  93. return cameraDeviceId;
  94. },
  95. /**
  96. * Set device id of the camera which is currently in use.
  97. * Empty string stands for default device.
  98. * @param {string} newId new camera device id
  99. */
  100. setCameraDeviceId: function (newId = '') {
  101. cameraDeviceId = newId;
  102. window.localStorage.cameraDeviceId = newId;
  103. },
  104. /**
  105. * Get device id of the microphone which is currently in use.
  106. * Empty string stands for default device.
  107. * @returns {String}
  108. */
  109. getMicDeviceId: function () {
  110. return micDeviceId;
  111. },
  112. /**
  113. * Set device id of the microphone which is currently in use.
  114. * Empty string stands for default device.
  115. * @param {string} newId new microphone device id
  116. */
  117. setMicDeviceId: function (newId = '') {
  118. micDeviceId = newId;
  119. window.localStorage.micDeviceId = newId;
  120. },
  121. /**
  122. * Get device id of the audio output device which is currently in use.
  123. * Empty string stands for default device.
  124. * @returns {String}
  125. */
  126. getAudioOutputDeviceId: function () {
  127. return JitsiMeetJS.getAudioOutputDevice();
  128. },
  129. /**
  130. * Set device id of the audio output device which is currently in use.
  131. * Empty string stands for default device.
  132. * @param {string} newId new audio output device id
  133. * @returns {Promise}
  134. */
  135. setAudioOutputDeviceId: function (newId = '') {
  136. return JitsiMeetJS.setAudioOutputDevice(newId)
  137. .then(() => window.localStorage.audioOutputDeviceId = newId);
  138. },
  139. /**
  140. * Check if welcome page is enabled or not.
  141. * @returns {boolean}
  142. */
  143. isWelcomePageEnabled () {
  144. return !welcomePageDisabled;
  145. },
  146. /**
  147. * Enable or disable welcome page.
  148. * @param {boolean} enabled if welcome page should be enabled or not
  149. */
  150. setWelcomePageEnabled (enabled) {
  151. welcomePageDisabled = !enabled;
  152. window.localStorage.welcomePageDisabled = welcomePageDisabled;
  153. }
  154. };