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

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