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

Settings.js 6.2KB

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