選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Settings.js 2.3KB

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