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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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",
  31. this.confSettings.jitsiMeetId);
  32. this.save();
  33. }
  34. if (!this.confSettings.callStatsUserName) {
  35. this.confSettings.callStatsUserName
  36. = UsernameGenerator.generateUsername();
  37. logger.log('generated callstats uid',
  38. this.confSettings.callStatsUserName);
  39. this.save();
  40. }
  41. this.userId = this.confSettings.jitsiMeetId || '';
  42. this.displayName = this.confSettings.displayname || '';
  43. this.callStatsUserName = this.confSettings.callStatsUserName || '';
  44. } else {
  45. logger.log("local storage is not supported");
  46. this.userId = generateUniqueId();
  47. this.callStatsUserName = UsernameGenerator.generateUsername();
  48. }
  49. }
  50. Settings.prototype.save = function () {
  51. if(!supportsLocalStorage())
  52. window.localStorage.setItem(this.conferenceID, JSON.stringify(this.confSettings));
  53. }
  54. Settings.prototype.setDisplayName = function (newDisplayName) {
  55. this.displayName = newDisplayName;
  56. if(this.confSettings != null)
  57. this.confSettings.displayname = displayName;
  58. this.save();
  59. return this.displayName;
  60. }
  61. Settings.prototype.getSettings = function () {
  62. return {
  63. displayName: this.displayName,
  64. uid: this.userId
  65. };
  66. }
  67. /**
  68. * Returns fake username for callstats
  69. * @returns {string} fake username for callstats
  70. */
  71. Settings.prototype.getCallStatsUserName = function () {
  72. return this.callStatsUserName;
  73. }
  74. module.exports = Settings;