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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* global JitsiMeetJS */
  2. import UIUtil from '../UI/util/UIUtil';
  3. import jitsiLocalStorage from '../util/JitsiLocalStorage';
  4. function generateUniqueId() {
  5. function _p8() {
  6. return (Math.random().toString(16) + "000000000").substr(2, 8);
  7. }
  8. return _p8() + _p8() + _p8() + _p8();
  9. }
  10. let avatarUrl = '';
  11. let email = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("email") || '');
  12. let avatarId = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("avatarId") || '');
  13. if (!avatarId) {
  14. // if there is no avatar id, we generate a unique one and use it forever
  15. avatarId = generateUniqueId();
  16. jitsiLocalStorage.setItem("avatarId", avatarId);
  17. }
  18. let localFlipX = JSON.parse(jitsiLocalStorage.getItem("localFlipX") || true);
  19. let displayName = UIUtil.unescapeHtml(
  20. jitsiLocalStorage.getItem("displayname") || '');
  21. let language = jitsiLocalStorage.getItem("language");
  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. console.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. getLanguage () {
  98. return language;
  99. },
  100. setLanguage: function (lang) {
  101. language = lang;
  102. jitsiLocalStorage.setItem("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. };