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

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