Browse Source

Fixes an issue where we skip calling callstats addNewFabric.

In case backend was initialized before creating our Callstats instance, we skip calling the callstats method addNewFabric.
tags/v0.0.2
damencho 8 years ago
parent
commit
1c743d65ee
1 changed files with 29 additions and 12 deletions
  1. 29
    12
      modules/statistics/CallStats.js

+ 29
- 12
modules/statistics/CallStats.js View File

106
             return;
106
             return;
107
         }
107
         }
108
 
108
 
109
+        CallStats.backendInitialized = true;
110
+
109
         // I hate that
111
         // I hate that
110
         let atLeastOneFabric = false;
112
         let atLeastOneFabric = false;
111
         let defaultInstance = null;
113
         let defaultInstance = null;
126
             return;
128
             return;
127
         }
129
         }
128
 
130
 
129
-        CallStats.initialized = true;
131
+        CallStats._emptyReportQueue(defaultInstance);
132
+    }
130
 
133
 
134
+    /**
135
+     * Empties report queue.
136
+     *
137
+     * @param {CallStats} csInstance - The callstats instance.
138
+     * @private
139
+     */
140
+    static _emptyReportQueue(csInstance) {
131
         // There is no conference ID nor a PeerConnection available when some of
141
         // There is no conference ID nor a PeerConnection available when some of
132
         // the events are scheduled on the reportsQueue, so those will be
142
         // the events are scheduled on the reportsQueue, so those will be
133
         // reported on the first initialized fabric.
143
         // reported on the first initialized fabric.
134
-        const defaultConfID = defaultInstance.confID;
135
-        const defaultPC = defaultInstance.peerconnection;
144
+        const defaultConfID = csInstance.confID;
145
+        const defaultPC = csInstance.peerconnection;
136
 
146
 
137
         // notify callstats about failures if there were any
147
         // notify callstats about failures if there were any
138
         for (const report of CallStats.reportsQueue) {
148
         for (const report of CallStats.reportsQueue) {
140
                 const errorData = report.data;
150
                 const errorData = report.data;
141
 
151
 
142
                 CallStats._reportError(
152
                 CallStats._reportError(
143
-                    defaultInstance,
153
+                    csInstance,
144
                     errorData.type,
154
                     errorData.type,
145
                     errorData.error,
155
                     errorData.error,
146
                     errorData.pc || defaultPC);
156
                     errorData.pc || defaultPC);
188
             logger.warn('No error is passed!');
198
             logger.warn('No error is passed!');
189
             _error = new Error('Unknown error');
199
             _error = new Error('Unknown error');
190
         }
200
         }
191
-        if (CallStats.initialized && cs) {
201
+        if (CallStats.backendInitialized && cs) {
192
             CallStats.backend.reportError(pc, cs.confID, type, _error);
202
             CallStats.backend.reportError(pc, cs.confID, type, _error);
193
         } else {
203
         } else {
194
             CallStats.reportsQueue.push({
204
             CallStats.reportsQueue.push({
218
         const pc = cs && cs.peerconnection;
228
         const pc = cs && cs.peerconnection;
219
         const confID = cs && cs.confID;
229
         const confID = cs && cs.confID;
220
 
230
 
221
-        if (CallStats.initialized && cs) {
231
+        if (CallStats.backendInitialized && cs) {
222
             CallStats.backend.sendFabricEvent(pc, event, confID, eventData);
232
             CallStats.backend.sendFabricEvent(pc, event, confID, eventData);
223
         } else {
233
         } else {
224
             CallStats.reportsQueue.push({
234
             CallStats.reportsQueue.push({
507
 
517
 
508
         CallStats.fabrics.add(this);
518
         CallStats.fabrics.add(this);
509
 
519
 
510
-        if (CallStats.initialized) {
520
+        if (CallStats.backendInitialized) {
511
             this._addNewFabric();
521
             this._addNewFabric();
522
+
523
+            // if this is the first fabric let's try to empty the
524
+            // report queue. Reports all events that we recorded between
525
+            // backend initialization and receiving the first fabric
526
+            if (CallStats.fabrics.size === 1) {
527
+                CallStats._emptyReportQueue(this);
528
+            }
512
         }
529
         }
513
     }
530
     }
514
 
531
 
580
 
597
 
581
         const callStatsId = isLocal ? CallStats.userID : streamEndpointId;
598
         const callStatsId = isLocal ? CallStats.userID : streamEndpointId;
582
 
599
 
583
-        if (CallStats.initialized) {
600
+        if (CallStats.backendInitialized) {
584
             CallStats.backend.associateMstWithUserID(
601
             CallStats.backend.associateMstWithUserID(
585
                 this.peerconnection,
602
                 this.peerconnection,
586
                 callStatsId,
603
                 callStatsId,
617
      * closed and no evens should be reported, after this call.
634
      * closed and no evens should be reported, after this call.
618
      */
635
      */
619
     sendTerminateEvent() {
636
     sendTerminateEvent() {
620
-        if (CallStats.initialized) {
637
+        if (CallStats.backendInitialized) {
621
             CallStats.backend.sendFabricEvent(
638
             CallStats.backend.sendFabricEvent(
622
                 this.peerconnection,
639
                 this.peerconnection,
623
                 CallStats.backend.fabricEvent.fabricTerminated,
640
                 CallStats.backend.fabricEvent.fabricTerminated,
722
 CallStats.reportsQueue = [];
739
 CallStats.reportsQueue = [];
723
 
740
 
724
 /**
741
 /**
725
- * Whether the library was successfully initialized using its initialize method.
726
- * And whether we had successfully called addNewFabric at least once.
742
+ * Whether the library was successfully initialized(the backend) using its
743
+ * initialize method.
727
  * @type {boolean}
744
  * @type {boolean}
728
  */
745
  */
729
-CallStats.initialized = false;
746
+CallStats.backendInitialized = false;
730
 
747
 
731
 /**
748
 /**
732
  * Part of the CallStats credentials - application ID
749
  * Part of the CallStats credentials - application ID

Loading…
Cancel
Save