Pārlūkot izejas kodu

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 gadus atpakaļ
vecāks
revīzija
16d3b2eacb
5 mainītis faili ar 72 papildinājumiem un 11 dzēšanām
  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 Parādīt failu

254
         // bellow).
254
         // bellow).
255
         const windowLocation = window.location;
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
         this.statistics = new Statistics(this.xmpp, {
263
         this.statistics = new Statistics(this.xmpp, {
258
-            callStatsAliasName: this.myUserId(),
264
+            callStatsAliasName,
259
             callStatsConfIDNamespace:
265
             callStatsConfIDNamespace:
260
                 config.callStatsConfIDNamespace
266
                 config.callStatsConfIDNamespace
261
                     || (windowLocation && windowLocation.hostname)
267
                     || (windowLocation && windowLocation.hostname)
263
             callStatsCustomScriptUrl: config.callStatsCustomScriptUrl,
269
             callStatsCustomScriptUrl: config.callStatsCustomScriptUrl,
264
             callStatsID: config.callStatsID,
270
             callStatsID: config.callStatsID,
265
             callStatsSecret: config.callStatsSecret,
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
  * @param role the role of the participant in the MUC
1145
  * @param role the role of the participant in the MUC
1139
  * @param isHidden indicates if this is a hidden participant (system
1146
  * @param isHidden indicates if this is a hidden participant (system
1140
  * participant for example a recorder).
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
     const id = Strophe.getResourceFromJid(jid);
1152
     const id = Strophe.getResourceFromJid(jid);
1144
 
1153
 
1145
     if (id === 'focus' || this.myUserId() === id) {
1154
     if (id === 'focus' || this.myUserId() === id) {
1146
         return;
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
     participant._role = role;
1160
     participant._role = role;
1151
     this.participants[id] = participant;
1161
     this.participants[id] = participant;
2107
         false /* initiator */, this.room, this.rtc);
2117
         false /* initiator */, this.room, this.rtc);
2108
 
2118
 
2109
     logger.info('Starting CallStats for P2P connection...');
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
     this.statistics.startCallStats(
2131
     this.statistics.startCallStats(
2111
         this.p2pJingleSession.peerconnection,
2132
         this.p2pJingleSession.peerconnection,
2112
-        Strophe.getResourceFromJid(this.p2pJingleSession.peerjid));
2133
+        remoteID);
2113
 
2134
 
2114
     const localTracks = this.getLocalTracks();
2135
     const localTracks = this.getLocalTracks();
2115
 
2136
 
2392
     this.p2pJingleSession.initialize(true /* initiator */, this.room, this.rtc);
2413
     this.p2pJingleSession.initialize(true /* initiator */, this.room, this.rtc);
2393
 
2414
 
2394
     logger.info('Starting CallStats for P2P connection...');
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
     this.statistics.startCallStats(
2427
     this.statistics.startCallStats(
2396
         this.p2pJingleSession.peerconnection,
2428
         this.p2pJingleSession.peerconnection,
2397
-        Strophe.getResourceFromJid(this.p2pJingleSession.peerjid));
2429
+        remoteID);
2398
 
2430
 
2399
     // NOTE one may consider to start P2P with the local tracks detached,
2431
     // NOTE one may consider to start P2P with the local tracks detached,
2400
     // but no data will be sent until ICE succeeds anyway. And we switch
2432
     // but no data will be sent until ICE succeeds anyway. And we switch

+ 10
- 1
JitsiParticipant.js Parādīt failu

20
      * @param displayName
20
      * @param displayName
21
      * @param {Boolean} hidden - True if the new JitsiParticipant instance is to
21
      * @param {Boolean} hidden - True if the new JitsiParticipant instance is to
22
      * represent a hidden participant; otherwise, false.
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
         this._jid = jid;
26
         this._jid = jid;
26
         this._id = Strophe.getResourceFromJid(jid);
27
         this._id = Strophe.getResourceFromJid(jid);
27
         this._conference = conference;
28
         this._conference = conference;
35
             video: undefined
36
             video: undefined
36
         };
37
         };
37
         this._hidden = hidden;
38
         this._hidden = hidden;
39
+        this._statsID = statsID;
38
         this._connectionStatus = ParticipantConnectionStatus.ACTIVE;
40
         this._connectionStatus = ParticipantConnectionStatus.ACTIVE;
39
         this._properties = {};
41
         this._properties = {};
40
     }
42
     }
151
         return this._displayName;
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
      * @returns {String} The status of the participant.
164
      * @returns {String} The status of the participant.
156
      */
165
      */

+ 4
- 1
doc/API.md Parādīt failu

224
         4. callStatsID - callstats credentials
224
         4. callStatsID - callstats credentials
225
         5. callStatsSecret - callstats credentials
225
         5. callStatsSecret - callstats credentials
226
         6. enableTalkWhileMuted - boolean property. Enables/disables talk while muted detection, by default the value is false/disabled.
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
         **NOTE: if 4 and 5 are set the library is going to send events to callstats. Otherwise the callstats integration will be disabled.**
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
 5. addEventListener(event, listener) - Subscribes the passed listener to the event.
233
 5. addEventListener(event, listener) - Subscribes the passed listener to the event.

+ 4
- 2
modules/statistics/statistics.js Parādīt failu

318
         if (!CallStats.initBackend({
318
         if (!CallStats.initBackend({
319
             callStatsID: this.options.callStatsID,
319
             callStatsID: this.options.callStatsID,
320
             callStatsSecret: this.options.callStatsSecret,
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
             // Backend initialization failed bad
327
             // Backend initialization failed bad

+ 16
- 1
modules/xmpp/ChatRoom.js Parādīt failu

7
 import * as MediaType from '../../service/RTC/MediaType';
7
 import * as MediaType from '../../service/RTC/MediaType';
8
 import Moderator from './moderator';
8
 import Moderator from './moderator';
9
 import Recorder from './recording';
9
 import Recorder from './recording';
10
+import Settings from '../settings/Settings';
10
 import XMPPEvents from '../../service/xmpp/XMPPEvents';
11
 import XMPPEvents from '../../service/xmpp/XMPPEvents';
11
 
12
 
12
 const logger = getLogger(__filename);
13
 const logger = getLogger(__filename);
195
             'attributes': { xmlns: 'http://jitsi.org/jitmeet/user-agent' }
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
         // We need to broadcast 'videomuted' status from the beginning, cause
206
         // We need to broadcast 'videomuted' status from the beginning, cause
199
         // Jicofo makes decisions based on that. Initialize it with 'false'
207
         // Jicofo makes decisions based on that. Initialize it with 'false'
200
         // here.
208
         // here.
441
             case 'userId':
449
             case 'userId':
442
                 member.id = node.value;
450
                 member.id = node.value;
443
                 break;
451
                 break;
452
+            case 'stats-id':
453
+                member.statsID = node.value;
454
+                break;
444
             }
455
             }
445
         }
456
         }
446
 
457
 
477
             } else {
488
             } else {
478
                 this.eventEmitter.emit(
489
                 this.eventEmitter.emit(
479
                     XMPPEvents.MUC_MEMBER_JOINED,
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
             hasStatusUpdate = member.status !== undefined;
498
             hasStatusUpdate = member.status !== undefined;

Notiek ielāde…
Atcelt
Saglabāt