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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var logger = require("jitsi-meet-logger").getLogger(__filename);
  2. function supportsLocalStorage() {
  3. try {
  4. return 'localStorage' in window && window.localStorage !== null;
  5. } catch (e) {
  6. logger.log("localstorage is not supported");
  7. return false;
  8. }
  9. }
  10. function generateUniqueId() {
  11. function _p8() {
  12. return (Math.random().toString(16) + "000000000").substr(2, 8);
  13. }
  14. return _p8() + _p8() + _p8() + _p8();
  15. }
  16. function Settings(conferenceID) {
  17. this.displayName = '';
  18. this.userId;
  19. this.confSettings = null;
  20. this.conferenceID = conferenceID;
  21. if (supportsLocalStorage()) {
  22. if(!window.localStorage.getItem(conferenceID))
  23. this.confSettings = {};
  24. else
  25. this.confSettings = JSON.parse(window.localStorage.getItem(conferenceID));
  26. if(!this.confSettings.jitsiMeetId) {
  27. this.confSettings.jitsiMeetId = generateUniqueId();
  28. logger.log("generated id",
  29. this.confSettings.jitsiMeetId);
  30. this.save();
  31. }
  32. this.userId = this.confSettings.jitsiMeetId || '';
  33. this.displayName = this.confSettings.displayname || '';
  34. } else {
  35. logger.log("local storage is not supported");
  36. this.userId = generateUniqueId();
  37. }
  38. }
  39. Settings.prototype.save = function () {
  40. if(!supportsLocalStorage())
  41. window.localStorage.setItem(this.conferenceID, JSON.stringify(this.confSettings));
  42. }
  43. Settings.prototype.setDisplayName = function (newDisplayName) {
  44. this.displayName = newDisplayName;
  45. if(this.confSettings != null)
  46. this.confSettings.displayname = displayName;
  47. this.save();
  48. return this.displayName;
  49. },
  50. Settings.prototype.getSettings = function () {
  51. return {
  52. displayName: this.displayName,
  53. uid: this.userId
  54. };
  55. },
  56. module.exports = Settings;