Browse Source

fix(logs&stats): BEFORE_STATISTICS_DISPOSED

Will emit BEFORE_STATISTICS_DISPOSED event, before the last CallStats
fabric is terminated to make sure that the final logs batch is reported
correctly.

Also adds a check for CallStats instance to queue events when
the backend has been initialized, but there is no CallStats instance
available to report on.
dev1
paweldomas 8 years ago
parent
commit
d5c87ff6b9
2 changed files with 23 additions and 4 deletions
  1. 3
    3
      modules/statistics/CallStats.js
  2. 20
    1
      modules/statistics/statistics.js

+ 3
- 3
modules/statistics/CallStats.js View File

@@ -182,8 +182,8 @@ export default class CallStats {
182 182
             logger.warn('No error is passed!');
183 183
             _error = new Error('Unknown error');
184 184
         }
185
-        if (CallStats.initialized) {
186
-            CallStats.backend.reportError(pc, cs && cs.confID, type, _error);
185
+        if (CallStats.initialized && cs) {
186
+            CallStats.backend.reportError(pc, cs.confID, type, _error);
187 187
         } else {
188 188
             CallStats.reportsQueue.push({
189 189
                 type: reportType.ERROR,
@@ -212,7 +212,7 @@ export default class CallStats {
212 212
         const pc = cs && cs.peerconnection;
213 213
         const confID = cs && cs.confID;
214 214
 
215
-        if (CallStats.initialized) {
215
+        if (CallStats.initialized && cs) {
216 216
             CallStats.backend.sendFabricEvent(pc, event, confID, eventData);
217 217
         } else {
218 218
             CallStats.reportsQueue.push({

+ 20
- 1
modules/statistics/statistics.js View File

@@ -204,7 +204,14 @@ Statistics.prototype.removeByteSentStatsListener = function(listener) {
204 204
 
205 205
 Statistics.prototype.dispose = function() {
206 206
     try {
207
-        if (this.eventEmitter) {
207
+        // NOTE Before reading this please see the comment in stopCallStats...
208
+        //
209
+        // Here we prevent from emitting the event twice in case it will be
210
+        // triggered from stopCallStats.
211
+        // If the event is triggered from here it means that the logs will not
212
+        // be submitted anyway (because there is no CallStats instance), but
213
+        // we're doing that for the sake of some kind of consistency.
214
+        if (!this.callsStatsInstances.size) {
208 215
             this.eventEmitter.emit(StatisticsEvents.BEFORE_DISPOSED);
209 216
         }
210 217
         for (const callStats of this.callsStatsInstances.values()) {
@@ -326,6 +333,18 @@ Statistics.prototype.stopCallStats = function(tpc) {
326 333
     const callStatsInstance = this.callsStatsInstances.get(tpc.id);
327 334
 
328 335
     if (callStatsInstance) {
336
+        // FIXME the original purpose of adding BEFORE_DISPOSED event was to be
337
+        // able to submit the last log batch from jitsi-meet to CallStats. After
338
+        // recent changes we dispose the CallStats earlier
339
+        // (before Statistics.dispose), so we need to emit this event here to
340
+        // give this last chance for final log batch submission.
341
+        //
342
+        // Eventually there should be a separate module called "log storage"
343
+        // which should emit proper events when it's underlying
344
+        // CallStats instance is going away.
345
+        if (this.callsStatsInstances.size === 1) {
346
+            this.eventEmitter.emit(StatisticsEvents.BEFORE_DISPOSED);
347
+        }
329 348
         this.callsStatsInstances.delete(tpc.id);
330 349
 
331 350
         // The fabric needs to be terminated when being stopped

Loading…
Cancel
Save