Pārlūkot izejas kodu

Merge pull request #479 from jitsi/p2p_analytics

Analytics for ICE checks and gathering durations
dev1
George Politis 8 gadus atpakaļ
vecāks
revīzija
5d6b024ab6
1 mainītis faili ar 61 papildinājumiem un 3 dzēšanām
  1. 61
    3
      modules/xmpp/JingleSessionPC.js

+ 61
- 3
modules/xmpp/JingleSessionPC.js Parādīt failu

69
             options) {
69
             options) {
70
         super(sid, me, peerjid, connection, mediaConstraints, iceConfig);
70
         super(sid, me, peerjid, connection, mediaConstraints, iceConfig);
71
 
71
 
72
+        /**
73
+         * Stores result of {@link window.performance.now()} at the time when
74
+         * ICE enters 'checking' state.
75
+         * @type {number|null} null if no value has been stored yet
76
+         * @private
77
+         */
78
+        this._iceCheckingStartedTimestamp = null;
79
+
80
+        /**
81
+         * Stores result of {@link window.performance.now()} at the time when
82
+         * first ICE candidate is spawned by the peerconnection to mark when
83
+         * ICE gathering started. That's, because ICE gathering state changed
84
+         * events are not supported by most of the browsers, so we try something
85
+         * that will work everywhere. It may not be as accurate, but given that
86
+         * 'host' candidate usually comes first, the delay should be minimal.
87
+         * @type {number|null} null if no value has been stored yet
88
+         * @private
89
+         */
90
+        this._gatheringStartedTimestamp = null;
91
+
92
+        /**
93
+         * Marks that ICE gathering duration has been reported already. That
94
+         * prevents reporting it again, after eventual 'transport-replace' (JVB
95
+         * conference migration/ICE restart).
96
+         * @type {boolean}
97
+         * @private
98
+         */
99
+        this._gatheringReported = false;
100
+
72
         this.lasticecandidate = false;
101
         this.lasticecandidate = false;
73
         this.closed = false;
102
         this.closed = false;
74
 
103
 
217
 
246
 
218
             // XXX this is broken, candidate is not parsed.
247
             // XXX this is broken, candidate is not parsed.
219
             const candidate = ev.candidate;
248
             const candidate = ev.candidate;
249
+            const now = window.performance.now();
220
 
250
 
221
             if (candidate) {
251
             if (candidate) {
252
+                if (this._gatheringStartedTimestamp === null) {
253
+                    this._gatheringStartedTimestamp = now;
254
+                }
255
+
222
                 // Discard candidates of disabled protocols.
256
                 // Discard candidates of disabled protocols.
223
                 let protocol = candidate.protocol;
257
                 let protocol = candidate.protocol;
224
 
258
 
234
                         }
268
                         }
235
                     }
269
                     }
236
                 }
270
                 }
271
+            } else if (!this._gatheringReported) {
272
+                // End of gathering
273
+                let eventName = this.isP2P ? 'p2p.ice.' : 'ice.';
274
+
275
+                eventName += this.isInitiator ? 'initiator' : 'responder';
276
+                eventName += '.gatheringDuration';
277
+                Statistics.analytics.sendEvent(
278
+                    eventName,
279
+                    { value: now - this._gatheringStartedTimestamp });
280
+                this._gatheringReported = true;
237
             }
281
             }
238
             this.sendIceCandidate(candidate);
282
             this.sendIceCandidate(candidate);
239
         };
283
         };
290
                 this,
334
                 this,
291
                 this.peerconnection.iceConnectionState);
335
                 this.peerconnection.iceConnectionState);
292
             switch (this.peerconnection.iceConnectionState) {
336
             switch (this.peerconnection.iceConnectionState) {
337
+            case 'checking':
338
+                this._iceCheckingStartedTimestamp = now;
339
+                break;
293
             case 'connected':
340
             case 'connected':
294
                 // Informs interested parties that the connection has been
341
                 // Informs interested parties that the connection has been
295
                 // restored.
342
                 // restored.
297
                     if (this.isreconnect) {
344
                     if (this.isreconnect) {
298
                         this.room.eventEmitter.emit(
345
                         this.room.eventEmitter.emit(
299
                             XMPPEvents.CONNECTION_RESTORED, this);
346
                             XMPPEvents.CONNECTION_RESTORED, this);
300
-                    } else if (!this.wasConnected) {
301
-                        this.room.eventEmitter.emit(
302
-                            XMPPEvents.CONNECTION_ESTABLISHED, this);
303
                     }
347
                     }
348
+                }
349
+
350
+                if (!this.wasConnected && this.wasstable) {
351
+                    let eventName = this.isP2P ? 'p2p.ice.' : 'ice.';
352
+
353
+                    eventName += this.isInitiator ? 'initiator.' : 'responder.';
354
+                    eventName += 'checksDuration';
355
+                    Statistics.analytics.sendEvent(
356
+                        eventName,
357
+                        {
358
+                            value: now - this._iceCheckingStartedTimestamp
359
+                        });
304
                     this.wasConnected = true;
360
                     this.wasConnected = true;
361
+                    this.room.eventEmitter.emit(
362
+                            XMPPEvents.CONNECTION_ESTABLISHED, this);
305
                 }
363
                 }
306
                 this.isreconnect = false;
364
                 this.isreconnect = false;
307
                 break;
365
                 break;

Notiek ielāde…
Atcelt
Saglabāt