Просмотр исходного кода

Merge pull request #479 from jitsi/p2p_analytics

Analytics for ICE checks and gathering durations
dev1
George Politis 8 лет назад
Родитель
Сommit
5d6b024ab6
1 измененных файлов: 61 добавлений и 3 удалений
  1. 61
    3
      modules/xmpp/JingleSessionPC.js

+ 61
- 3
modules/xmpp/JingleSessionPC.js Просмотреть файл

@@ -69,6 +69,35 @@ export default class JingleSessionPC extends JingleSession {
69 69
             options) {
70 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 101
         this.lasticecandidate = false;
73 102
         this.closed = false;
74 103
 
@@ -217,8 +246,13 @@ export default class JingleSessionPC extends JingleSession {
217 246
 
218 247
             // XXX this is broken, candidate is not parsed.
219 248
             const candidate = ev.candidate;
249
+            const now = window.performance.now();
220 250
 
221 251
             if (candidate) {
252
+                if (this._gatheringStartedTimestamp === null) {
253
+                    this._gatheringStartedTimestamp = now;
254
+                }
255
+
222 256
                 // Discard candidates of disabled protocols.
223 257
                 let protocol = candidate.protocol;
224 258
 
@@ -234,6 +268,16 @@ export default class JingleSessionPC extends JingleSession {
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 282
             this.sendIceCandidate(candidate);
239 283
         };
@@ -290,6 +334,9 @@ export default class JingleSessionPC extends JingleSession {
290 334
                 this,
291 335
                 this.peerconnection.iceConnectionState);
292 336
             switch (this.peerconnection.iceConnectionState) {
337
+            case 'checking':
338
+                this._iceCheckingStartedTimestamp = now;
339
+                break;
293 340
             case 'connected':
294 341
                 // Informs interested parties that the connection has been
295 342
                 // restored.
@@ -297,11 +344,22 @@ export default class JingleSessionPC extends JingleSession {
297 344
                     if (this.isreconnect) {
298 345
                         this.room.eventEmitter.emit(
299 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 360
                     this.wasConnected = true;
361
+                    this.room.eventEmitter.emit(
362
+                            XMPPEvents.CONNECTION_ESTABLISHED, this);
305 363
                 }
306 364
                 this.isreconnect = false;
307 365
                 break;

Загрузка…
Отмена
Сохранить