|
|
@@ -2,11 +2,14 @@ var logger = require("jitsi-meet-logger").getLogger(__filename);
|
|
2
|
2
|
|
|
3
|
3
|
var UsernameGenerator = require('../util/UsernameGenerator');
|
|
4
|
4
|
|
|
|
5
|
+/**
|
|
|
6
|
+ * Check if browser supports localStorage.
|
|
|
7
|
+ * @returns {boolean} true if supports, false otherwise
|
|
|
8
|
+ */
|
|
5
|
9
|
function supportsLocalStorage() {
|
|
6
|
10
|
try {
|
|
7
|
11
|
return 'localStorage' in window && window.localStorage !== null;
|
|
8
|
12
|
} catch (e) {
|
|
9
|
|
- logger.log("localstorage is not supported");
|
|
10
|
13
|
return false;
|
|
11
|
14
|
}
|
|
12
|
15
|
}
|
|
|
@@ -19,62 +22,68 @@ function generateUniqueId() {
|
|
19
|
22
|
return _p8() + _p8() + _p8() + _p8();
|
|
20
|
23
|
}
|
|
21
|
24
|
|
|
22
|
|
-function Settings(conferenceID) {
|
|
23
|
|
- this.displayName = '';
|
|
|
25
|
+/**
|
|
|
26
|
+ * Generate unique id.
|
|
|
27
|
+ * @returns {string} random unique id
|
|
|
28
|
+ */
|
|
|
29
|
+function generateJitsiMeetId() {
|
|
|
30
|
+ var jitsiMeetId = generateUniqueId();
|
|
|
31
|
+ logger.log("generated id", jitsiMeetId);
|
|
|
32
|
+
|
|
|
33
|
+ return jitsiMeetId;
|
|
|
34
|
+}
|
|
|
35
|
+
|
|
|
36
|
+/**
|
|
|
37
|
+ * Generate fake username for callstats.
|
|
|
38
|
+ * @returns {string} fake random username
|
|
|
39
|
+ */
|
|
|
40
|
+function generateCallStatsUsername() {
|
|
|
41
|
+ var username = UsernameGenerator.generateUsername();
|
|
|
42
|
+ logger.log('generated callstats uid', username);
|
|
|
43
|
+
|
|
|
44
|
+ return username;
|
|
|
45
|
+}
|
|
|
46
|
+
|
|
|
47
|
+function Settings() {
|
|
24
|
48
|
this.userId;
|
|
25
|
|
- this.confSettings = null;
|
|
26
|
|
- this.conferenceID = conferenceID;
|
|
27
|
49
|
this.callStatsUserName;
|
|
|
50
|
+
|
|
28
|
51
|
if (supportsLocalStorage()) {
|
|
29
|
|
- if(!window.localStorage.getItem(conferenceID))
|
|
30
|
|
- this.confSettings = {};
|
|
31
|
|
- else
|
|
32
|
|
- this.confSettings = JSON.parse(window.localStorage.getItem(conferenceID));
|
|
33
|
|
- if(!this.confSettings.jitsiMeetId) {
|
|
34
|
|
- this.confSettings.jitsiMeetId = generateUniqueId();
|
|
35
|
|
- logger.log("generated id", this.confSettings.jitsiMeetId);
|
|
36
|
|
- this.save();
|
|
37
|
|
- }
|
|
38
|
|
- if (!this.confSettings.callStatsUserName) {
|
|
39
|
|
- this.confSettings.callStatsUserName
|
|
40
|
|
- = UsernameGenerator.generateUsername();
|
|
41
|
|
- logger.log('generated callstats uid',
|
|
42
|
|
- this.confSettings.callStatsUserName);
|
|
43
|
|
- this.save();
|
|
44
|
|
- }
|
|
45
|
|
-
|
|
46
|
|
- this.userId = this.confSettings.jitsiMeetId || '';
|
|
47
|
|
- this.displayName = this.confSettings.displayname || '';
|
|
48
|
|
- this.callStatsUserName = this.confSettings.callStatsUserName || '';
|
|
|
52
|
+ this.userId = window.localStorage.getItem('jitsiMeetId')
|
|
|
53
|
+ || generateJitsiMeetId();
|
|
|
54
|
+
|
|
|
55
|
+
|
|
|
56
|
+ this.callStatsUserName = window.localStorage.getItem(
|
|
|
57
|
+ 'callStatsUserName'
|
|
|
58
|
+ ) || generateCallStatsUsername();
|
|
|
59
|
+
|
|
|
60
|
+ this.save();
|
|
49
|
61
|
} else {
|
|
50
|
|
- logger.log("local storage is not supported");
|
|
51
|
|
- this.userId = generateUniqueId();
|
|
52
|
|
- this.callStatsUserName = UsernameGenerator.generateUsername();
|
|
|
62
|
+ logger.log("localStorage is not supported");
|
|
|
63
|
+ this.userId = generateJitsiMeetId();
|
|
|
64
|
+ this.callStatsUserName = generateCallStatsUsername();
|
|
53
|
65
|
}
|
|
54
|
66
|
}
|
|
55
|
67
|
|
|
|
68
|
+/**
|
|
|
69
|
+ * Save settings to localStorage if browser supports that.
|
|
|
70
|
+ */
|
|
56
|
71
|
Settings.prototype.save = function () {
|
|
57
|
|
- if (supportsLocalStorage()) {
|
|
58
|
|
- window.localStorage.setItem(
|
|
59
|
|
- this.conferenceID, JSON.stringify(this.confSettings)
|
|
60
|
|
- );
|
|
|
72
|
+ if (!supportsLocalStorage()) {
|
|
|
73
|
+ return;
|
|
61
|
74
|
}
|
|
62
|
|
-};
|
|
63
|
75
|
|
|
64
|
|
-Settings.prototype.setDisplayName = function (newDisplayName) {
|
|
65
|
|
- this.displayName = newDisplayName;
|
|
66
|
|
- if(this.confSettings != null)
|
|
67
|
|
- this.confSettings.displayname = displayName;
|
|
68
|
|
- this.save();
|
|
69
|
|
- return this.displayName;
|
|
70
|
|
-}
|
|
|
76
|
+ window.localStorage.setItem('jitsiMeetId', this.userId);
|
|
|
77
|
+ window.localStorage.setItem('callStatsUserName', this.callStatsUserName);
|
|
|
78
|
+};
|
|
71
|
79
|
|
|
72
|
|
-Settings.prototype.getSettings = function () {
|
|
73
|
|
- return {
|
|
74
|
|
- displayName: this.displayName,
|
|
75
|
|
- uid: this.userId
|
|
76
|
|
- };
|
|
77
|
|
-}
|
|
|
80
|
+/**
|
|
|
81
|
+ * Returns current user id.
|
|
|
82
|
+ * @returns {string} user id
|
|
|
83
|
+ */
|
|
|
84
|
+Settings.prototype.getUserId = function () {
|
|
|
85
|
+ return this.userId;
|
|
|
86
|
+};
|
|
78
|
87
|
|
|
79
|
88
|
/**
|
|
80
|
89
|
* Returns fake username for callstats
|
|
|
@@ -82,6 +91,36 @@ Settings.prototype.getSettings = function () {
|
|
82
|
91
|
*/
|
|
83
|
92
|
Settings.prototype.getCallStatsUserName = function () {
|
|
84
|
93
|
return this.callStatsUserName;
|
|
85
|
|
-}
|
|
|
94
|
+};
|
|
|
95
|
+
|
|
|
96
|
+/**
|
|
|
97
|
+ * Save current session id.
|
|
|
98
|
+ * @param {string} sessionId session id
|
|
|
99
|
+ */
|
|
|
100
|
+Settings.prototype.setSessionId = function (sessionId) {
|
|
|
101
|
+ if (sessionId) {
|
|
|
102
|
+ window.localStorage.setItem('sessionId', sessionId);
|
|
|
103
|
+ } else {
|
|
|
104
|
+ window.localStorage.removeItem('sessionId');
|
|
|
105
|
+ }
|
|
|
106
|
+};
|
|
|
107
|
+
|
|
|
108
|
+/**
|
|
|
109
|
+ * Clear current session id.
|
|
|
110
|
+ */
|
|
|
111
|
+Settings.prototype.clearSessionId = function () {
|
|
|
112
|
+ this.setSessionId(undefined);
|
|
|
113
|
+};
|
|
|
114
|
+
|
|
|
115
|
+/**
|
|
|
116
|
+ * Returns current session id.
|
|
|
117
|
+ * @returns {string} current session id
|
|
|
118
|
+ */
|
|
|
119
|
+Settings.prototype.getSessionId = function () {
|
|
|
120
|
+ // we can update session id in localStorage from
|
|
|
121
|
+ // another JitsiConference instance
|
|
|
122
|
+ // thats why we should always re-read it
|
|
|
123
|
+ return window.localStorage.getItem('sessionId');
|
|
|
124
|
+};
|
|
86
|
125
|
|
|
87
|
126
|
module.exports = Settings;
|