Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Settings.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. // Currently audio output device change is supported only in Chrome and
  20. // default output always has 'default' device ID
  21. const audioOutputDeviceId = jitsiLocalStorage.getItem('audioOutputDeviceId')
  22. || 'default';
  23. if (audioOutputDeviceId
  24. !== JitsiMeetJS.mediaDevices.getAudioOutputDevice()) {
  25. JitsiMeetJS.mediaDevices.setAudioOutputDevice(audioOutputDeviceId)
  26. .catch(ex => {
  27. logger.warn('Failed to set audio output device from local '
  28. + 'storage. Default audio output device will be used'
  29. + 'instead.', ex);
  30. });
  31. }
  32. export default {
  33. /**
  34. * Sets the local user display name and saves it to local storage
  35. *
  36. * @param {string} newDisplayName unescaped display name for the local user
  37. * @param {boolean} disableLocalStore disables local store the display name
  38. */
  39. setDisplayName(newDisplayName, disableLocalStore) {
  40. displayName = newDisplayName;
  41. if (!disableLocalStore) {
  42. jitsiLocalStorage.setItem('displayname',
  43. UIUtil.escapeHtml(displayName));
  44. }
  45. },
  46. /**
  47. * Returns the escaped display name currently used by the user
  48. * @returns {string} currently valid user display name.
  49. */
  50. getDisplayName() {
  51. return displayName;
  52. },
  53. /**
  54. * Sets new email for local user and saves it to the local storage.
  55. * @param {string} newEmail new email for the local user
  56. * @param {boolean} disableLocalStore disables local store the email
  57. */
  58. setEmail(newEmail, disableLocalStore) {
  59. email = newEmail;
  60. if (!disableLocalStore) {
  61. jitsiLocalStorage.setItem('email', UIUtil.escapeHtml(newEmail));
  62. }
  63. },
  64. /**
  65. * Returns email address of the local user.
  66. * @returns {string} email
  67. */
  68. getEmail() {
  69. return email;
  70. },
  71. /**
  72. * Returns avatar id of the local user.
  73. * @returns {string} avatar id
  74. */
  75. getAvatarId() {
  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(newAvatarUrl) {
  83. avatarUrl = newAvatarUrl;
  84. },
  85. /**
  86. * Returns avatarUrl address of the local user.
  87. * @returns {string} avatarUrl
  88. */
  89. getAvatarUrl() {
  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(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() {
  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() {
  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(newId, store) {
  122. cameraDeviceId = newId;
  123. if (store) {
  124. jitsiLocalStorage.setItem('cameraDeviceId', newId);
  125. }
  126. },
  127. /**
  128. * Get device id of the microphone which is currently in use.
  129. * Empty string stands for default device.
  130. * @returns {String}
  131. */
  132. getMicDeviceId() {
  133. return micDeviceId;
  134. },
  135. /**
  136. * Set device id of the microphone which is currently in use.
  137. * Empty string stands for default device.
  138. * @param {string} newId new microphone device id
  139. * @param {boolean} whether we need to store the value
  140. */
  141. setMicDeviceId(newId, store) {
  142. micDeviceId = newId;
  143. if (store) {
  144. jitsiLocalStorage.setItem('micDeviceId', newId);
  145. }
  146. },
  147. /**
  148. * Get device id of the audio output device which is currently in use.
  149. * Empty string stands for default device.
  150. * @returns {String}
  151. */
  152. getAudioOutputDeviceId() {
  153. return JitsiMeetJS.mediaDevices.getAudioOutputDevice();
  154. },
  155. /**
  156. * Set device id of the audio output device which is currently in use.
  157. * Empty string stands for default device.
  158. * @param {string} newId='default' - new audio output device id
  159. * @returns {Promise}
  160. */
  161. setAudioOutputDeviceId(newId = 'default') {
  162. return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
  163. .then(() =>
  164. jitsiLocalStorage.setItem('audioOutputDeviceId', newId));
  165. }
  166. };