소스 검색

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.
dev1
damencho 8 년 전
부모
커밋
1c743d65ee
1개의 변경된 파일29개의 추가작업 그리고 12개의 파일을 삭제
  1. 29
    12
      modules/statistics/CallStats.js

+ 29
- 12
modules/statistics/CallStats.js 파일 보기

@@ -106,6 +106,8 @@ export default class CallStats {
106 106
             return;
107 107
         }
108 108
 
109
+        CallStats.backendInitialized = true;
110
+
109 111
         // I hate that
110 112
         let atLeastOneFabric = false;
111 113
         let defaultInstance = null;
@@ -126,13 +128,21 @@ export default class CallStats {
126 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 141
         // There is no conference ID nor a PeerConnection available when some of
132 142
         // the events are scheduled on the reportsQueue, so those will be
133 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 147
         // notify callstats about failures if there were any
138 148
         for (const report of CallStats.reportsQueue) {
@@ -140,7 +150,7 @@ export default class CallStats {
140 150
                 const errorData = report.data;
141 151
 
142 152
                 CallStats._reportError(
143
-                    defaultInstance,
153
+                    csInstance,
144 154
                     errorData.type,
145 155
                     errorData.error,
146 156
                     errorData.pc || defaultPC);
@@ -188,7 +198,7 @@ export default class CallStats {
188 198
             logger.warn('No error is passed!');
189 199
             _error = new Error('Unknown error');
190 200
         }
191
-        if (CallStats.initialized && cs) {
201
+        if (CallStats.backendInitialized && cs) {
192 202
             CallStats.backend.reportError(pc, cs.confID, type, _error);
193 203
         } else {
194 204
             CallStats.reportsQueue.push({
@@ -218,7 +228,7 @@ export default class CallStats {
218 228
         const pc = cs && cs.peerconnection;
219 229
         const confID = cs && cs.confID;
220 230
 
221
-        if (CallStats.initialized && cs) {
231
+        if (CallStats.backendInitialized && cs) {
222 232
             CallStats.backend.sendFabricEvent(pc, event, confID, eventData);
223 233
         } else {
224 234
             CallStats.reportsQueue.push({
@@ -507,8 +517,15 @@ export default class CallStats {
507 517
 
508 518
         CallStats.fabrics.add(this);
509 519
 
510
-        if (CallStats.initialized) {
520
+        if (CallStats.backendInitialized) {
511 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,7 +597,7 @@ export default class CallStats {
580 597
 
581 598
         const callStatsId = isLocal ? CallStats.userID : streamEndpointId;
582 599
 
583
-        if (CallStats.initialized) {
600
+        if (CallStats.backendInitialized) {
584 601
             CallStats.backend.associateMstWithUserID(
585 602
                 this.peerconnection,
586 603
                 callStatsId,
@@ -617,7 +634,7 @@ export default class CallStats {
617 634
      * closed and no evens should be reported, after this call.
618 635
      */
619 636
     sendTerminateEvent() {
620
-        if (CallStats.initialized) {
637
+        if (CallStats.backendInitialized) {
621 638
             CallStats.backend.sendFabricEvent(
622 639
                 this.peerconnection,
623 640
                 CallStats.backend.fabricEvent.fabricTerminated,
@@ -722,11 +739,11 @@ CallStats.backend = null;
722 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 744
  * @type {boolean}
728 745
  */
729
-CallStats.initialized = false;
746
+CallStats.backendInitialized = false;
730 747
 
731 748
 /**
732 749
  * Part of the CallStats credentials - application ID

Loading…
취소
저장