Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Settings.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. jitsiLocalStorage.setItem("language", lang);
  104. },
  105. /**
  106. * Sets new flipX state of local video and saves it to the local storage.
  107. * @param {string} val flipX state of local video
  108. */
  109. setLocalFlipX: function (val) {
  110. localFlipX = val;
  111. jitsiLocalStorage.setItem("localFlipX", val);
  112. },
  113. /**
  114. * Returns flipX state of local video.
  115. * @returns {string} flipX
  116. */
  117. getLocalFlipX: function () {
  118. return localFlipX;
  119. },
  120. /**
  121. * Get device id of the camera which is currently in use.
  122. * Empty string stands for default device.
  123. * @returns {String}
  124. */
  125. getCameraDeviceId: function () {
  126. return cameraDeviceId;
  127. },
  128. /**
  129. * Set device id of the camera which is currently in use.
  130. * Empty string stands for default device.
  131. * @param {string} newId new camera device id
  132. * @param {boolean} whether we need to store the value
  133. */
  134. setCameraDeviceId: function (newId, store) {
  135. cameraDeviceId = newId;
  136. if (store)
  137. jitsiLocalStorage.setItem("cameraDeviceId", newId);
  138. },
  139. /**
  140. * Get device id of the microphone which is currently in use.
  141. * Empty string stands for default device.
  142. * @returns {String}
  143. */
  144. getMicDeviceId: function () {
  145. return micDeviceId;
  146. },
  147. /**
  148. * Set device id of the microphone which is currently in use.
  149. * Empty string stands for default device.
  150. * @param {string} newId new microphone device id
  151. * @param {boolean} whether we need to store the value
  152. */
  153. setMicDeviceId: function (newId, store) {
  154. micDeviceId = newId;
  155. if (store)
  156. jitsiLocalStorage.setItem("micDeviceId", newId);
  157. },
  158. /**
  159. * Get device id of the audio output device which is currently in use.
  160. * Empty string stands for default device.
  161. * @returns {String}
  162. */
  163. getAudioOutputDeviceId: function () {
  164. return JitsiMeetJS.mediaDevices.getAudioOutputDevice();
  165. },
  166. /**
  167. * Set device id of the audio output device which is currently in use.
  168. * Empty string stands for default device.
  169. * @param {string} newId='default' - new audio output device id
  170. * @returns {Promise}
  171. */
  172. setAudioOutputDeviceId: function (newId = 'default') {
  173. return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
  174. .then(() =>
  175. jitsiLocalStorage.setItem("audioOutputDeviceId", newId));
  176. },
  177. /**
  178. * Check if welcome page is enabled or not.
  179. * @returns {boolean}
  180. */
  181. isWelcomePageEnabled () {
  182. return !welcomePageDisabled;
  183. },
  184. /**
  185. * Enable or disable welcome page.
  186. * @param {boolean} enabled if welcome page should be enabled or not
  187. */
  188. setWelcomePageEnabled (enabled) {
  189. welcomePageDisabled = !enabled;
  190. jitsiLocalStorage.setItem("welcomePageDisabled", welcomePageDisabled);
  191. }
  192. };