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

Settings.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /* global JitsiMeetJS */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. import UIUtil from '../UI/util/UIUtil';
  4. import jitsiLocalStorage from '../util/JitsiLocalStorage';
  5. function generateUniqueId() {
  6. function _p8() {
  7. return (Math.random().toString(16) + "000000000").substr(2, 8);
  8. }
  9. return _p8() + _p8() + _p8() + _p8();
  10. }
  11. let avatarUrl = '';
  12. let email = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("email") || '');
  13. let avatarId = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("avatarId") || '');
  14. if (!avatarId) {
  15. // if there is no avatar id, we generate a unique one and use it forever
  16. avatarId = generateUniqueId();
  17. jitsiLocalStorage.setItem("avatarId", avatarId);
  18. }
  19. let localFlipX = JSON.parse(jitsiLocalStorage.getItem("localFlipX") || true);
  20. let displayName = UIUtil.unescapeHtml(
  21. jitsiLocalStorage.getItem("displayname") || '');
  22. let language = jitsiLocalStorage.getItem("language");
  23. let cameraDeviceId = jitsiLocalStorage.getItem("cameraDeviceId") || '';
  24. let micDeviceId = jitsiLocalStorage.getItem("micDeviceId") || '';
  25. let welcomePageDisabled = JSON.parse(
  26. jitsiLocalStorage.getItem("welcomePageDisabled") || false);
  27. // Currently audio output device change is supported only in Chrome and
  28. // default output always has 'default' device ID
  29. let audioOutputDeviceId = jitsiLocalStorage.getItem("audioOutputDeviceId")
  30. || 'default';
  31. if (audioOutputDeviceId !==
  32. JitsiMeetJS.mediaDevices.getAudioOutputDevice()) {
  33. JitsiMeetJS.mediaDevices.setAudioOutputDevice(audioOutputDeviceId)
  34. .catch((ex) => {
  35. logger.warn('Failed to set audio output device from local ' +
  36. 'storage. Default audio output device will be used' +
  37. 'instead.', ex);
  38. });
  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. * @param {boolean} disableLocalStore disables local store the display name
  46. */
  47. setDisplayName (newDisplayName, disableLocalStore) {
  48. displayName = newDisplayName;
  49. if (!disableLocalStore)
  50. jitsiLocalStorage.setItem("displayname",
  51. UIUtil.escapeHtml(displayName));
  52. },
  53. /**
  54. * Returns the escaped display name currently used by the user
  55. * @returns {string} currently valid user display name.
  56. */
  57. getDisplayName: function () {
  58. return displayName;
  59. },
  60. /**
  61. * Sets new email for local user and saves it to the local storage.
  62. * @param {string} newEmail new email for the local user
  63. * @param {boolean} disableLocalStore disables local store the email
  64. */
  65. setEmail: function (newEmail, disableLocalStore) {
  66. email = newEmail;
  67. if (!disableLocalStore)
  68. jitsiLocalStorage.setItem("email", UIUtil.escapeHtml(newEmail));
  69. },
  70. /**
  71. * Returns email address of the local user.
  72. * @returns {string} email
  73. */
  74. getEmail: function () {
  75. return email;
  76. },
  77. /**
  78. * Returns avatar id of the local user.
  79. * @returns {string} avatar id
  80. */
  81. getAvatarId: function () {
  82. return avatarId;
  83. },
  84. /**
  85. * Sets new avatarUrl for local user and saves it to the local storage.
  86. * @param {string} newAvatarUrl new avatarUrl for the local user
  87. */
  88. setAvatarUrl: function (newAvatarUrl) {
  89. avatarUrl = newAvatarUrl;
  90. },
  91. /**
  92. * Returns avatarUrl address of the local user.
  93. * @returns {string} avatarUrl
  94. */
  95. getAvatarUrl: function () {
  96. return avatarUrl;
  97. },
  98. getLanguage () {
  99. return language;
  100. },
  101. setLanguage: function (lang) {
  102. language = lang;
  103. },
  104. /**
  105. * Sets new flipX state of local video and saves it to the local storage.
  106. * @param {string} val flipX state of local video
  107. */
  108. setLocalFlipX: function (val) {
  109. localFlipX = val;
  110. jitsiLocalStorage.setItem("localFlipX", val);
  111. },
  112. /**
  113. * Returns flipX state of local video.
  114. * @returns {string} flipX
  115. */
  116. getLocalFlipX: function () {
  117. return localFlipX;
  118. },
  119. /**
  120. * Get device id of the camera which is currently in use.
  121. * Empty string stands for default device.
  122. * @returns {String}
  123. */
  124. getCameraDeviceId: function () {
  125. return cameraDeviceId;
  126. },
  127. /**
  128. * Set device id of the camera which is currently in use.
  129. * Empty string stands for default device.
  130. * @param {string} newId new camera device id
  131. * @param {boolean} whether we need to store the value
  132. */
  133. setCameraDeviceId: function (newId, store) {
  134. cameraDeviceId = newId;
  135. if (store)
  136. jitsiLocalStorage.setItem("cameraDeviceId", newId);
  137. },
  138. /**
  139. * Get device id of the microphone which is currently in use.
  140. * Empty string stands for default device.
  141. * @returns {String}
  142. */
  143. getMicDeviceId: function () {
  144. return micDeviceId;
  145. },
  146. /**
  147. * Set device id of the microphone which is currently in use.
  148. * Empty string stands for default device.
  149. * @param {string} newId new microphone device id
  150. * @param {boolean} whether we need to store the value
  151. */
  152. setMicDeviceId: function (newId, store) {
  153. micDeviceId = newId;
  154. if (store)
  155. jitsiLocalStorage.setItem("micDeviceId", newId);
  156. },
  157. /**
  158. * Get device id of the audio output device which is currently in use.
  159. * Empty string stands for default device.
  160. * @returns {String}
  161. */
  162. getAudioOutputDeviceId: function () {
  163. return JitsiMeetJS.mediaDevices.getAudioOutputDevice();
  164. },
  165. /**
  166. * Set device id of the audio output device which is currently in use.
  167. * Empty string stands for default device.
  168. * @param {string} newId='default' - new audio output device id
  169. * @returns {Promise}
  170. */
  171. setAudioOutputDeviceId: function (newId = 'default') {
  172. return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
  173. .then(() =>
  174. jitsiLocalStorage.setItem("audioOutputDeviceId", newId));
  175. },
  176. /**
  177. * Check if welcome page is enabled or not.
  178. * @returns {boolean}
  179. */
  180. isWelcomePageEnabled () {
  181. return !welcomePageDisabled;
  182. },
  183. /**
  184. * Enable or disable welcome page.
  185. * @param {boolean} enabled if welcome page should be enabled or not
  186. */
  187. setWelcomePageEnabled (enabled) {
  188. welcomePageDisabled = !enabled;
  189. jitsiLocalStorage.setItem("welcomePageDisabled", welcomePageDisabled);
  190. }
  191. };