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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. var logger = require("jitsi-meet-logger").getLogger(__filename);
  2. var UsernameGenerator = require('../util/UsernameGenerator');
  3. function supportsLocalStorage() {
  4. try {
  5. return 'localStorage' in window && window.localStorage !== null;
  6. } catch (e) {
  7. logger.log("localstorage is not supported");
  8. return false;
  9. }
  10. }
  11. function generateUniqueId() {
  12. function _p8() {
  13. return (Math.random().toString(16) + "000000000").substr(2, 8);
  14. }
  15. return _p8() + _p8() + _p8() + _p8();
  16. }
  17. function Settings(conferenceID) {
  18. this.displayName = '';
  19. this.userId;
  20. this.confSettings = null;
  21. this.conferenceID = conferenceID;
  22. this.callStatsUserName;
  23. if (supportsLocalStorage()) {
  24. if(!window.localStorage.getItem(conferenceID))
  25. this.confSettings = {};
  26. else
  27. this.confSettings = JSON.parse(window.localStorage.getItem(conferenceID));
  28. if(!this.confSettings.jitsiMeetId) {
  29. this.confSettings.jitsiMeetId = generateUniqueId();
  30. logger.log("generated id", this.confSettings.jitsiMeetId);
  31. this.save();
  32. }
  33. if (!this.confSettings.callStatsUserName) {
  34. this.confSettings.callStatsUserName
  35. = UsernameGenerator.generateUsername();
  36. logger.log('generated callstats uid',
  37. this.confSettings.callStatsUserName);
  38. this.save();
  39. }
  40. this.userId = this.confSettings.jitsiMeetId || '';
  41. this.displayName = this.confSettings.displayname || '';
  42. this.callStatsUserName = this.confSettings.callStatsUserName || '';
  43. } else {
  44. logger.log("local storage is not supported");
  45. this.userId = generateUniqueId();
  46. this.callStatsUserName = UsernameGenerator.generateUsername();
  47. }
  48. }
  49. Settings.prototype.save = function () {
  50. if (supportsLocalStorage()) {
  51. window.localStorage.setItem(
  52. this.conferenceID, JSON.stringify(this.confSettings)
  53. );
  54. }
  55. };
  56. Settings.prototype.setDisplayName = function (newDisplayName) {
  57. this.displayName = newDisplayName;
  58. if(this.confSettings != null)
  59. this.confSettings.displayname = displayName;
  60. this.save();
  61. return this.displayName;
  62. }
  63. Settings.prototype.getSettings = function () {
  64. return {
  65. displayName: this.displayName,
  66. uid: this.userId
  67. };
  68. }
  69. /**
  70. * Returns fake username for callstats
  71. * @returns {string} fake username for callstats
  72. */
  73. Settings.prototype.getCallStatsUserName = function () {
  74. return this.callStatsUserName;
  75. }
  76. module.exports = Settings;