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 6.3KB

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