瀏覽代碼

Simplifies logic around userID and callstatsUsername in callstats.

master
damencho 5 年之前
父節點
當前提交
e6e6b890bb
共有 4 個檔案被更改,包括 41 行新增26 行删除
  1. 20
    4
      JitsiConference.js
  2. 10
    6
      modules/statistics/AnalyticsAdapter.js
  3. 9
    13
      modules/statistics/statistics.js
  4. 2
    3
      modules/xmpp/ChatRoom.js

+ 20
- 4
JitsiConference.js 查看文件

@@ -26,6 +26,7 @@ import E2ePing from './modules/e2eping/e2eping';
26 26
 import Jvb121EventGenerator from './modules/event/Jvb121EventGenerator';
27 27
 import RecordingManager from './modules/recording/RecordingManager';
28 28
 import RttMonitor from './modules/rttmonitor/rttmonitor';
29
+import Settings from './modules/settings/Settings';
29 30
 import AvgRTPStatsReporter from './modules/statistics/AvgRTPStatsReporter';
30 31
 import AudioOutputProblemDetector from './modules/statistics/AudioOutputProblemDetector';
31 32
 import SpeakerStatsCollector from './modules/statistics/SpeakerStatsCollector';
@@ -284,6 +285,11 @@ JitsiConference.prototype._init = function(options = {}) {
284 285
     }
285 286
 
286 287
     const { config } = this.options;
288
+    const statsCurrentId = Settings.callStatsUserName;
289
+
290
+    if (config.enableStatsID) {
291
+        config.statsId = statsCurrentId;
292
+    }
287 293
 
288 294
     this.room = this.xmpp.createRoom(
289 295
         this.options.name,
@@ -344,21 +350,31 @@ JitsiConference.prototype._init = function(options = {}) {
344 350
     this.participantConnectionStatus.init();
345 351
 
346 352
     if (!this.statistics) {
347
-        let callStatsAliasName = this.myUserId();
353
+        let aliasName = this.myUserId();
354
+        let userName = statsCurrentId;
348 355
 
349 356
         if (config.enableDisplayNameInStats && config.displayName) {
350
-            callStatsAliasName = config.displayName;
357
+            aliasName = config.displayName;
358
+        }
359
+
360
+        if (config.enableStatsID) {
361
+            // let's swap the values, as instead of components to report
362
+            // the xmpp resource as id will use the supplied statsId
363
+            const newAlias = userName;
364
+
365
+            userName = aliasName;
366
+            aliasName = newAlias;
351 367
         }
352 368
 
353 369
         this.statistics = new Statistics(this.xmpp, {
354
-            callStatsAliasName,
370
+            aliasName,
371
+            userName,
355 372
             callStatsConfIDNamespace: this.connection.options.hosts.domain,
356 373
             confID: config.confID || `${this.connection.options.hosts.domain}/${this.options.name}`,
357 374
             customScriptUrl: config.callStatsCustomScriptUrl,
358 375
             callStatsID: config.callStatsID,
359 376
             callStatsSecret: config.callStatsSecret,
360 377
             roomName: this.options.name,
361
-            swapUserNameAndAlias: config.enableStatsID,
362 378
             applicationName: config.applicationName,
363 379
             getWiFiStatsMethod: config.getWiFiStatsMethod
364 380
         });

+ 10
- 6
modules/statistics/AnalyticsAdapter.js 查看文件

@@ -6,7 +6,6 @@ import {
6 6
 } from '../../service/statistics/AnalyticsEvents';
7 7
 import { getLogger } from 'jitsi-meet-logger';
8 8
 import browser from '../browser';
9
-import Settings from '../settings/Settings';
10 9
 
11 10
 const MAX_CACHE_SIZE = 100;
12 11
 
@@ -55,11 +54,18 @@ const logger = getLogger(__filename);
55 54
  * action, actionSubject, source, containerType, containerId, objectType,
56 55
  * objectId
57 56
  */
58
-class AnalyticsAdapter {
57
+export default class AnalyticsAdapter {
58
+    /**
59
+     * The options to configure Statistics.
60
+     * @typedef {Object} AnalyticsOptions
61
+     * @property {string} statsId - The id that will be used to be passed with all analytics for current session.
62
+     */
59 63
     /**
60 64
      * Creates new AnalyticsAdapter instance.
65
+     * @param {AnalyticsOptions} options - The options to use creating the AnalyticsAdapter.
61 66
      */
62
-    constructor() {
67
+    constructor(options) {
68
+        this.options = options;
63 69
         this.reset();
64 70
     }
65 71
 
@@ -104,7 +110,7 @@ class AnalyticsAdapter {
104 110
         this.conferenceName = '';
105 111
 
106 112
         this.addPermanentProperties({
107
-            'callstats_name': Settings.callStatsUserName,
113
+            'callstats_name': this.options.statsId,
108 114
             'user_agent': navigator.userAgent,
109 115
             'browser_name': browser.getName()
110 116
         });
@@ -351,5 +357,3 @@ class AnalyticsAdapter {
351 357
         }
352 358
     }
353 359
 }
354
-
355
-export default new AnalyticsAdapter();

+ 9
- 13
modules/statistics/statistics.js 查看文件

@@ -1,13 +1,12 @@
1 1
 import EventEmitter from 'events';
2 2
 
3 3
 import { FEEDBACK } from '../../service/statistics/AnalyticsEvents';
4
-import analytics from './AnalyticsAdapter';
4
+import Analytics from './AnalyticsAdapter';
5 5
 import CallStats from './CallStats';
6 6
 import LocalStats from './LocalStatsCollector';
7 7
 import RTPStats from './RTPStatsCollector';
8 8
 
9 9
 import browser from '../browser';
10
-import Settings from '../settings/Settings';
11 10
 import ScriptUtil from '../util/ScriptUtil';
12 11
 import JitsiTrackError from '../../JitsiTrackError';
13 12
 import * as StatisticsEvents from '../../service/statistics/Events';
@@ -63,15 +62,11 @@ function _initCallStatsBackend(options) {
63 62
         return;
64 63
     }
65 64
 
66
-    const userName = Settings.callStatsUserName;
67
-
68 65
     if (!CallStats.initBackend({
69 66
         callStatsID: options.callStatsID,
70 67
         callStatsSecret: options.callStatsSecret,
71
-        userName: options.swapUserNameAndAlias
72
-            ? options.callStatsAliasName : userName,
73
-        aliasName: options.swapUserNameAndAlias
74
-            ? userName : options.callStatsAliasName,
68
+        userName: options.userName,
69
+        aliasName: options.aliasName,
75 70
         applicationName: options.applicationName,
76 71
         getWiFiStatsMethod: options.getWiFiStatsMethod,
77 72
         confID: options.confID
@@ -128,8 +123,8 @@ Statistics.init = function(options) {
128 123
  * @typedef {Object} StatisticsOptions
129 124
  * @property {string} applicationName - The application name to pass to
130 125
  * callstats.
131
- * @property {string} callStatsAliasName - The alias name to use when
132
- * initializing callstats.
126
+ * @property {string} aliasName - The alias name to use when initializing callstats.
127
+ * @property {string} userName - The user name to use when initializing callstats.
133 128
  * @property {string} callStatsConfIDNamespace - A namespace to prepend the
134 129
  * callstats conference ID with.
135 130
  * @property {string} confID - The callstats conference ID to use.
@@ -138,8 +133,6 @@ Statistics.init = function(options) {
138 133
  * @property {string} customScriptUrl - A custom lib url to use when downloading
139 134
  * callstats library.
140 135
  * @property {string} roomName - The room name we are currently in.
141
- * @property {boolean} swapUserNameAndAlias - Whether to swap the places of
142
- * username and alias when initiating callstats.
143 136
  */
144 137
 /**
145 138
  *
@@ -158,6 +151,10 @@ export default function Statistics(xmpp, options) {
158 151
     this.xmpp = xmpp;
159 152
     this.options = options || {};
160 153
 
154
+    Statistics.analytics = new Analytics({
155
+        statsId: this.options.aliasName
156
+    });
157
+
161 158
     this.callStatsIntegrationEnabled
162 159
         = this.options.callStatsID && this.options.callStatsSecret
163 160
 
@@ -194,7 +191,6 @@ export default function Statistics(xmpp, options) {
194 191
 Statistics.audioLevelsEnabled = false;
195 192
 Statistics.audioLevelsInterval = 200;
196 193
 Statistics.disableThirdPartyRequests = false;
197
-Statistics.analytics = analytics;
198 194
 
199 195
 Object.defineProperty(Statistics, 'instances', {
200 196
     /**

+ 2
- 3
modules/xmpp/ChatRoom.js 查看文件

@@ -6,7 +6,6 @@ import { $iq, $msg, $pres, Strophe } from 'strophe.js';
6 6
 import GlobalOnErrorHandler from '../util/GlobalOnErrorHandler';
7 7
 import * as JitsiTranscriptionStatus from '../../JitsiTranscriptionStatus';
8 8
 import Listenable from '../util/Listenable';
9
-import Settings from '../settings/Settings';
10 9
 import * as MediaType from '../../service/RTC/MediaType';
11 10
 import XMPPEvents from '../../service/xmpp/XMPPEvents';
12 11
 
@@ -140,10 +139,10 @@ export default class ChatRoom extends Listenable {
140 139
         this.presMap.xns = 'http://jabber.org/protocol/muc';
141 140
         this.presMap.nodes = [];
142 141
 
143
-        if (options.enableStatsID) {
142
+        if (options.statsId) {
144 143
             this.presMap.nodes.push({
145 144
                 'tagName': 'stats-id',
146
-                'value': Settings.callStatsUserName
145
+                'value': options.statsId
147 146
             });
148 147
         }
149 148
 

Loading…
取消
儲存