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.

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