Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Settings.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import {generateUsername} from '../util/UsernameGenerator';
  2. import UIUtil from '../UI/util/UIUtil';
  3. let email = '';
  4. let displayName = '';
  5. let userId;
  6. let language = null;
  7. let cameraDeviceId = '';
  8. let micDeviceId = '';
  9. function supportsLocalStorage() {
  10. try {
  11. return 'localStorage' in window && window.localStorage !== null;
  12. } catch (e) {
  13. console.log("localstorage is not supported");
  14. return false;
  15. }
  16. }
  17. function generateUniqueId() {
  18. function _p8() {
  19. return (Math.random().toString(16) + "000000000").substr(2, 8);
  20. }
  21. return _p8() + _p8() + _p8() + _p8();
  22. }
  23. if (supportsLocalStorage()) {
  24. if (!window.localStorage.jitsiMeetId) {
  25. window.localStorage.jitsiMeetId = generateUniqueId();
  26. console.log("generated id", window.localStorage.jitsiMeetId);
  27. }
  28. userId = window.localStorage.jitsiMeetId || '';
  29. email = window.localStorage.email || '';
  30. displayName = UIUtil.unescapeHtml(window.localStorage.displayname || '');
  31. language = window.localStorage.language;
  32. cameraDeviceId = window.localStorage.cameraDeviceId || '';
  33. micDeviceId = window.localStorage.micDeviceId || '';
  34. } else {
  35. console.log("local storage is not supported");
  36. userId = generateUniqueId();
  37. }
  38. export default {
  39. /**
  40. * Sets the local user display name and saves it to local storage
  41. *
  42. * @param {string} newDisplayName unescaped display name for the local user
  43. */
  44. setDisplayName (newDisplayName) {
  45. displayName = newDisplayName;
  46. window.localStorage.displayname = UIUtil.escapeHtml(displayName);
  47. },
  48. /**
  49. * Returns the escaped display name currently used by the user
  50. * @returns {string} currently valid user display name.
  51. */
  52. getDisplayName: function () {
  53. return displayName;
  54. },
  55. /**
  56. * Returns id of the user.
  57. * @returns {string} user id
  58. */
  59. getUserId () {
  60. return userId;
  61. },
  62. setEmail: function (newEmail) {
  63. email = newEmail;
  64. window.localStorage.email = newEmail;
  65. return email;
  66. },
  67. getEmail: function () {
  68. return email;
  69. },
  70. getSettings: function () {
  71. return {
  72. email: email,
  73. displayName: displayName,
  74. uid: userId,
  75. language: language
  76. };
  77. },
  78. getLanguage () {
  79. return language;
  80. },
  81. setLanguage: function (lang) {
  82. language = lang;
  83. window.localStorage.language = lang;
  84. },
  85. /**
  86. * Get device id of the camera which is currently in use.
  87. * Empty string stands for default device.
  88. * @returns {String}
  89. */
  90. getCameraDeviceId: function () {
  91. return cameraDeviceId;
  92. },
  93. /**
  94. * Set device id of the camera which is currently in use.
  95. * Empty string stands for default device.
  96. * @param {string} newId new camera device id
  97. */
  98. setCameraDeviceId: function (newId = '') {
  99. cameraDeviceId = newId;
  100. window.localStorage.cameraDeviceId = newId;
  101. },
  102. /**
  103. * Get device id of the microphone which is currently in use.
  104. * Empty string stands for default device.
  105. * @returns {String}
  106. */
  107. getMicDeviceId: function () {
  108. return micDeviceId;
  109. },
  110. /**
  111. * Set device id of the microphone which is currently in use.
  112. * Empty string stands for default device.
  113. * @param {string} newId new microphone device id
  114. */
  115. setMicDeviceId: function (newId = '') {
  116. micDeviceId = newId;
  117. window.localStorage.micDeviceId = newId;
  118. }
  119. };