|
@@ -3,123 +3,77 @@ const logger = getLogger(__filename);
|
3
|
3
|
|
4
|
4
|
import UsernameGenerator from '../util/UsernameGenerator';
|
5
|
5
|
|
6
|
|
-/**
|
7
|
|
- * Gets the localStorage of the browser. (Technically, gets the localStorage of
|
8
|
|
- * the global object because there may be no browser but React Native for
|
9
|
|
- * example).
|
10
|
|
- * @returns {Storage} the local Storage object (if any)
|
11
|
|
- */
|
12
|
|
-function getLocalStorage() {
|
13
|
|
-
|
14
|
|
- // eslint-disable-next-line no-invalid-this
|
15
|
|
- const global = typeof window === 'undefined' ? this : window;
|
16
|
|
- let storage;
|
|
6
|
+let _callStatsUserName;
|
17
|
7
|
|
18
|
|
- try {
|
19
|
|
- storage = global.localStorage;
|
20
|
|
- } catch (error) {
|
21
|
|
- logger.error(error);
|
22
|
|
- }
|
23
|
|
-
|
24
|
|
- return storage;
|
25
|
|
-}
|
26
|
|
-
|
27
|
|
-/**
|
28
|
|
- *
|
29
|
|
- */
|
30
|
|
-function _p8() {
|
31
|
|
- return `${Math.random().toString(16)}000000000`.substr(2, 8);
|
32
|
|
-}
|
|
8
|
+let _machineId;
|
33
|
9
|
|
34
|
10
|
/**
|
35
|
11
|
*
|
36
|
12
|
*/
|
37
|
|
-function generateUniqueId() {
|
38
|
|
- return _p8() + _p8() + _p8() + _p8();
|
39
|
|
-}
|
40
|
|
-
|
41
|
|
-/**
|
42
|
|
- * Generate unique id.
|
43
|
|
- * @returns {string} random unique id
|
44
|
|
- */
|
45
|
|
-function generateJitsiMeetId() {
|
46
|
|
- const jitsiMeetId = generateUniqueId();
|
47
|
|
-
|
48
|
|
- logger.log('generated id', jitsiMeetId);
|
49
|
|
-
|
50
|
|
- return jitsiMeetId;
|
51
|
|
-}
|
52
|
|
-
|
53
|
|
-/**
|
54
|
|
- * Generate fake username for callstats.
|
55
|
|
- * @returns {string} fake random username
|
56
|
|
- */
|
57
|
|
-function generateCallStatsUsername() {
|
58
|
|
- const username = UsernameGenerator.generateUsername();
|
59
|
|
-
|
60
|
|
- logger.log('generated callstats uid', username);
|
61
|
|
-
|
62
|
|
- return username;
|
63
|
|
-}
|
64
|
|
-
|
65
|
|
-/**
|
66
|
|
- *
|
67
|
|
- */
|
68
|
|
-class Settings {
|
|
13
|
+export default {
|
69
|
14
|
/**
|
70
|
|
- *
|
|
15
|
+ * Returns fake username for callstats
|
|
16
|
+ * @returns {string} fake username for callstats
|
71
|
17
|
*/
|
72
|
|
- constructor() {
|
73
|
|
- const localStorage = getLocalStorage();
|
|
18
|
+ get callStatsUserName() {
|
|
19
|
+ if (!_callStatsUserName) {
|
|
20
|
+ const localStorage = getLocalStorage();
|
74
|
21
|
|
75
|
|
- if (localStorage) {
|
76
|
|
- this.userId
|
77
|
|
- = localStorage.getItem('jitsiMeetId') || generateJitsiMeetId();
|
78
|
|
- this.callStatsUserName
|
79
|
|
- = localStorage.getItem('callStatsUserName')
|
80
|
|
- || generateCallStatsUsername();
|
81
|
|
-
|
82
|
|
- this.save();
|
83
|
|
- } else {
|
84
|
|
- logger.log('localStorage is not supported');
|
85
|
|
- this.userId = generateJitsiMeetId();
|
86
|
|
- this.callStatsUserName = generateCallStatsUsername();
|
|
22
|
+ if (localStorage) {
|
|
23
|
+ _callStatsUserName = localStorage.getItem('callStatsUserName');
|
|
24
|
+ }
|
|
25
|
+ if (!_callStatsUserName) {
|
|
26
|
+ _callStatsUserName = generateCallStatsUserName();
|
|
27
|
+ if (localStorage) {
|
|
28
|
+ localStorage.setItem(
|
|
29
|
+ 'callStatsUserName',
|
|
30
|
+ _callStatsUserName);
|
|
31
|
+ }
|
|
32
|
+ }
|
87
|
33
|
}
|
88
|
|
- }
|
89
|
34
|
|
90
|
|
- /**
|
91
|
|
- * Save settings to localStorage if browser supports that.
|
92
|
|
- */
|
93
|
|
- save() {
|
94
|
|
- const localStorage = getLocalStorage();
|
95
|
|
-
|
96
|
|
- if (localStorage) {
|
97
|
|
- localStorage.setItem('jitsiMeetId', this.userId);
|
98
|
|
- localStorage.setItem('callStatsUserName', this.callStatsUserName);
|
99
|
|
- }
|
100
|
|
- }
|
|
35
|
+ return _callStatsUserName;
|
|
36
|
+ },
|
101
|
37
|
|
102
|
38
|
/**
|
103
|
39
|
* Returns current machine id.
|
104
|
40
|
* @returns {string} machine id
|
105
|
41
|
*/
|
106
|
|
- getMachineId() {
|
107
|
|
- return this.userId;
|
108
|
|
- }
|
|
42
|
+ get machineId() {
|
|
43
|
+ if (!_machineId) {
|
|
44
|
+ const localStorage = getLocalStorage();
|
|
45
|
+
|
|
46
|
+ if (localStorage) {
|
|
47
|
+ _machineId = localStorage.getItem('jitsiMeetId');
|
|
48
|
+ }
|
|
49
|
+ if (!_machineId) {
|
|
50
|
+ _machineId = generateJitsiMeetId();
|
|
51
|
+ if (localStorage) {
|
|
52
|
+ localStorage.setItem('jitsiMeetId', _machineId);
|
|
53
|
+ }
|
|
54
|
+ }
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ return _machineId;
|
|
58
|
+ },
|
109
|
59
|
|
110
|
60
|
/**
|
111
|
|
- * Returns fake username for callstats
|
112
|
|
- * @returns {string} fake username for callstats
|
|
61
|
+ * Returns current session id.
|
|
62
|
+ * @returns {string} current session id
|
113
|
63
|
*/
|
114
|
|
- getCallStatsUserName() {
|
115
|
|
- return this.callStatsUserName;
|
116
|
|
- }
|
|
64
|
+ get sessionId() {
|
|
65
|
+ // We may update sessionId in localStorage from another JitsiConference
|
|
66
|
+ // instance and that's why we should always re-read it.
|
|
67
|
+ const localStorage = getLocalStorage();
|
|
68
|
+
|
|
69
|
+ return localStorage ? localStorage.getItem('sessionId') : undefined;
|
|
70
|
+ },
|
117
|
71
|
|
118
|
72
|
/**
|
119
|
73
|
* Save current session id.
|
120
|
74
|
* @param {string} sessionId session id
|
121
|
75
|
*/
|
122
|
|
- setSessionId(sessionId) {
|
|
76
|
+ set sessionId(sessionId) {
|
123
|
77
|
const localStorage = getLocalStorage();
|
124
|
78
|
|
125
|
79
|
if (localStorage) {
|
|
@@ -130,26 +84,61 @@ class Settings {
|
130
|
84
|
}
|
131
|
85
|
}
|
132
|
86
|
}
|
|
87
|
+};
|
133
|
88
|
|
134
|
|
- /**
|
135
|
|
- * Clear current session id.
|
136
|
|
- */
|
137
|
|
- clearSessionId() {
|
138
|
|
- this.setSessionId(undefined);
|
139
|
|
- }
|
|
89
|
+/**
|
|
90
|
+ * Generate fake username for callstats.
|
|
91
|
+ * @returns {string} fake random username
|
|
92
|
+ */
|
|
93
|
+function generateCallStatsUserName() {
|
|
94
|
+ const username = UsernameGenerator.generateUsername();
|
140
|
95
|
|
141
|
|
- /**
|
142
|
|
- * Returns current session id.
|
143
|
|
- * @returns {string} current session id
|
144
|
|
- */
|
145
|
|
- getSessionId() {
|
146
|
|
- // We may update sessionId in localStorage from another JitsiConference
|
147
|
|
- // instance and that's why we should always re-read it.
|
148
|
|
- const localStorage = getLocalStorage();
|
|
96
|
+ logger.log('generated callstats uid', username);
|
149
|
97
|
|
|
98
|
+ return username;
|
|
99
|
+}
|
150
|
100
|
|
151
|
|
- return localStorage ? localStorage.getItem('sessionId') : undefined;
|
|
101
|
+/**
|
|
102
|
+ * Generate unique id.
|
|
103
|
+ * @returns {string} random unique id
|
|
104
|
+ */
|
|
105
|
+function generateJitsiMeetId() {
|
|
106
|
+ const jitsiMeetId = generateUniqueId();
|
|
107
|
+
|
|
108
|
+ logger.log('generated id', jitsiMeetId);
|
|
109
|
+
|
|
110
|
+ return jitsiMeetId;
|
|
111
|
+}
|
|
112
|
+
|
|
113
|
+/**
|
|
114
|
+ * Gets the localStorage of the browser. (Technically, gets the localStorage of
|
|
115
|
+ * the global object because there may be no browser but React Native for
|
|
116
|
+ * example).
|
|
117
|
+ * @returns {Storage} the local Storage object (if any)
|
|
118
|
+ */
|
|
119
|
+function getLocalStorage() {
|
|
120
|
+ let storage;
|
|
121
|
+
|
|
122
|
+ try {
|
|
123
|
+ // eslint-disable-next-line no-invalid-this
|
|
124
|
+ storage = (window || this).localStorage;
|
|
125
|
+ } catch (error) {
|
|
126
|
+ logger.error(error);
|
152
|
127
|
}
|
|
128
|
+
|
|
129
|
+ return storage;
|
153
|
130
|
}
|
154
|
131
|
|
155
|
|
-export default new Settings();
|
|
132
|
+/**
|
|
133
|
+ *
|
|
134
|
+ */
|
|
135
|
+function generateUniqueId() {
|
|
136
|
+ return _p8() + _p8() + _p8() + _p8();
|
|
137
|
+}
|
|
138
|
+
|
|
139
|
+/**
|
|
140
|
+ *
|
|
141
|
+ */
|
|
142
|
+function _p8() {
|
|
143
|
+ return `${Math.random().toString(16)}000000000`.substr(2, 8);
|
|
144
|
+}
|