Browse Source

Uses optional statsId to report to callstats and push it to presence. (#608)

* Uses optional statsId to report to callstats and push it to presence.

The feature is behind a flag which is disabled by default.

* Renames statsId to statsID.

* Fixes doc.
dev1
Дамян Минков 8 years ago
parent
commit
16d3b2eacb
5 changed files with 72 additions and 11 deletions
  1. 38
    6
      JitsiConference.js
  2. 10
    1
      JitsiParticipant.js
  3. 4
    1
      doc/API.md
  4. 4
    2
      modules/statistics/statistics.js
  5. 16
    1
      modules/xmpp/ChatRoom.js

+ 38
- 6
JitsiConference.js View File

@@ -254,8 +254,14 @@ JitsiConference.prototype._init = function(options = {}) {
254 254
         // bellow).
255 255
         const windowLocation = window.location;
256 256
 
257
+        let callStatsAliasName = this.myUserId();
258
+
259
+        if (config.enableDisplayNameInStats && config.displayName) {
260
+            callStatsAliasName = config.displayName;
261
+        }
262
+
257 263
         this.statistics = new Statistics(this.xmpp, {
258
-            callStatsAliasName: this.myUserId(),
264
+            callStatsAliasName,
259 265
             callStatsConfIDNamespace:
260 266
                 config.callStatsConfIDNamespace
261 267
                     || (windowLocation && windowLocation.hostname)
@@ -263,7 +269,8 @@ JitsiConference.prototype._init = function(options = {}) {
263 269
             callStatsCustomScriptUrl: config.callStatsCustomScriptUrl,
264 270
             callStatsID: config.callStatsID,
265 271
             callStatsSecret: config.callStatsSecret,
266
-            roomName: this.options.name
272
+            roomName: this.options.name,
273
+            swapUserNameAndAlias: config.enableStatsID
267 274
         });
268 275
     }
269 276
 
@@ -1138,14 +1145,17 @@ JitsiConference.prototype.muteParticipant = function(id) {
1138 1145
  * @param role the role of the participant in the MUC
1139 1146
  * @param isHidden indicates if this is a hidden participant (system
1140 1147
  * participant for example a recorder).
1148
+ * @param statsID the participant statsID (optional)
1141 1149
  */
1142
-JitsiConference.prototype.onMemberJoined = function(jid, nick, role, isHidden) {
1150
+JitsiConference.prototype.onMemberJoined = function(
1151
+        jid, nick, role, isHidden, statsID) {
1143 1152
     const id = Strophe.getResourceFromJid(jid);
1144 1153
 
1145 1154
     if (id === 'focus' || this.myUserId() === id) {
1146 1155
         return;
1147 1156
     }
1148
-    const participant = new JitsiParticipant(jid, this, nick, isHidden);
1157
+    const participant
1158
+        = new JitsiParticipant(jid, this, nick, isHidden, statsID);
1149 1159
 
1150 1160
     participant._role = role;
1151 1161
     this.participants[id] = participant;
@@ -2107,9 +2117,20 @@ JitsiConference.prototype._acceptP2PIncomingCall = function(
2107 2117
         false /* initiator */, this.room, this.rtc);
2108 2118
 
2109 2119
     logger.info('Starting CallStats for P2P connection...');
2120
+
2121
+    let remoteID = Strophe.getResourceFromJid(this.p2pJingleSession.peerjid);
2122
+
2123
+    if (this.options.config.enableStatsID) {
2124
+        const participant = this.participants[remoteID];
2125
+
2126
+        if (participant) {
2127
+            remoteID = participant.getStatsID() || remoteID;
2128
+        }
2129
+    }
2130
+
2110 2131
     this.statistics.startCallStats(
2111 2132
         this.p2pJingleSession.peerconnection,
2112
-        Strophe.getResourceFromJid(this.p2pJingleSession.peerjid));
2133
+        remoteID);
2113 2134
 
2114 2135
     const localTracks = this.getLocalTracks();
2115 2136
 
@@ -2392,9 +2413,20 @@ JitsiConference.prototype._startP2PSession = function(peerJid) {
2392 2413
     this.p2pJingleSession.initialize(true /* initiator */, this.room, this.rtc);
2393 2414
 
2394 2415
     logger.info('Starting CallStats for P2P connection...');
2416
+
2417
+    let remoteID = Strophe.getResourceFromJid(this.p2pJingleSession.peerjid);
2418
+
2419
+    if (this.options.config.enableStatsID) {
2420
+        const participant = this.participants[remoteID];
2421
+
2422
+        if (participant) {
2423
+            remoteID = participant.getStatsID() || remoteID;
2424
+        }
2425
+    }
2426
+
2395 2427
     this.statistics.startCallStats(
2396 2428
         this.p2pJingleSession.peerconnection,
2397
-        Strophe.getResourceFromJid(this.p2pJingleSession.peerjid));
2429
+        remoteID);
2398 2430
 
2399 2431
     // NOTE one may consider to start P2P with the local tracks detached,
2400 2432
     // but no data will be sent until ICE succeeds anyway. And we switch

+ 10
- 1
JitsiParticipant.js View File

@@ -20,8 +20,9 @@ export default class JitsiParticipant {
20 20
      * @param displayName
21 21
      * @param {Boolean} hidden - True if the new JitsiParticipant instance is to
22 22
      * represent a hidden participant; otherwise, false.
23
+     * @param {string} statsID - optional participant statsID
23 24
      */
24
-    constructor(jid, conference, displayName, hidden) {
25
+    constructor(jid, conference, displayName, hidden, statsID) {
25 26
         this._jid = jid;
26 27
         this._id = Strophe.getResourceFromJid(jid);
27 28
         this._conference = conference;
@@ -35,6 +36,7 @@ export default class JitsiParticipant {
35 36
             video: undefined
36 37
         };
37 38
         this._hidden = hidden;
39
+        this._statsID = statsID;
38 40
         this._connectionStatus = ParticipantConnectionStatus.ACTIVE;
39 41
         this._properties = {};
40 42
     }
@@ -151,6 +153,13 @@ export default class JitsiParticipant {
151 153
         return this._displayName;
152 154
     }
153 155
 
156
+    /**
157
+     * @returns {String} The stats ID of this participant.
158
+     */
159
+    getStatsID() {
160
+        return this._statsID;
161
+    }
162
+
154 163
     /**
155 164
      * @returns {String} The status of the participant.
156 165
      */

+ 4
- 1
doc/API.md View File

@@ -224,7 +224,10 @@ This objects represents the server connection. You can create new ```JitsiConnec
224 224
         4. callStatsID - callstats credentials
225 225
         5. callStatsSecret - callstats credentials
226 226
         6. enableTalkWhileMuted - boolean property. Enables/disables talk while muted detection, by default the value is false/disabled.
227
-        7. ignoreStartMuted - ignores start muted events coming from jicofo. 
227
+        7. ignoreStartMuted - ignores start muted events coming from jicofo.
228
+        8. enableStatsID - enables sending callStatsUsername as stats-id in presence, jicofo and videobridge will use it as endpointID to report stats
229
+        9. enableDisplayNameInStats - enables sending the users display name, if set, to callstats as alias of the endpointID stats 
230
+
228 231
         **NOTE: if 4 and 5 are set the library is going to send events to callstats. Otherwise the callstats integration will be disabled.**
229 232
 
230 233
 5. addEventListener(event, listener) - Subscribes the passed listener to the event.

+ 4
- 2
modules/statistics/statistics.js View File

@@ -318,8 +318,10 @@ Statistics.prototype.startCallStats = function(tpc, remoteUserID) {
318 318
         if (!CallStats.initBackend({
319 319
             callStatsID: this.options.callStatsID,
320 320
             callStatsSecret: this.options.callStatsSecret,
321
-            userName,
322
-            aliasName: this.options.callStatsAliasName
321
+            userName: this.options.swapUserNameAndAlias
322
+                ? this.options.callStatsAliasName : userName,
323
+            aliasName: this.options.swapUserNameAndAlias
324
+                ? userName : this.options.callStatsAliasName
323 325
         })) {
324 326
 
325 327
             // Backend initialization failed bad

+ 16
- 1
modules/xmpp/ChatRoom.js View File

@@ -7,6 +7,7 @@ import Listenable from '../util/Listenable';
7 7
 import * as MediaType from '../../service/RTC/MediaType';
8 8
 import Moderator from './moderator';
9 9
 import Recorder from './recording';
10
+import Settings from '../settings/Settings';
10 11
 import XMPPEvents from '../../service/xmpp/XMPPEvents';
11 12
 
12 13
 const logger = getLogger(__filename);
@@ -195,6 +196,13 @@ export default class ChatRoom extends Listenable {
195 196
             'attributes': { xmlns: 'http://jitsi.org/jitmeet/user-agent' }
196 197
         });
197 198
 
199
+        if (options.enableStatsID) {
200
+            this.presMap.nodes.push({
201
+                'tagName': 'stats-id',
202
+                'value': Settings.callStatsUserName
203
+            });
204
+        }
205
+
198 206
         // We need to broadcast 'videomuted' status from the beginning, cause
199 207
         // Jicofo makes decisions based on that. Initialize it with 'false'
200 208
         // here.
@@ -441,6 +449,9 @@ export default class ChatRoom extends Listenable {
441 449
             case 'userId':
442 450
                 member.id = node.value;
443 451
                 break;
452
+            case 'stats-id':
453
+                member.statsID = node.value;
454
+                break;
444 455
             }
445 456
         }
446 457
 
@@ -477,7 +488,11 @@ export default class ChatRoom extends Listenable {
477 488
             } else {
478 489
                 this.eventEmitter.emit(
479 490
                     XMPPEvents.MUC_MEMBER_JOINED,
480
-                    from, member.nick, member.role, member.isHiddenDomain);
491
+                    from,
492
+                    member.nick,
493
+                    member.role,
494
+                    member.isHiddenDomain,
495
+                    member.statsID);
481 496
             }
482 497
 
483 498
             hasStatusUpdate = member.status !== undefined;

Loading…
Cancel
Save