Bug 1207575 - Fix reporting of Loop's connection status if a user exits a room and then re-enters it without reloading the room. r=Mardak
authorMark Banner <standard8@mozilla.com>
Fri, 25 Sep 2015 18:55:53 +0100
changeset 264685 5505a568b4846f16719f7253e990dac5980bfba9
parent 264684 254536401af29e174e0bb28bd6a90bf235e205f6
child 264686 760f14443b762f9c5de8794273209181de352523
push id65707
push usercbook@mozilla.com
push dateMon, 28 Sep 2015 12:18:34 +0000
treeherdermozilla-inbound@2c0e60a8f736 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMardak
bugs1207575
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1207575 - Fix reporting of Loop's connection status if a user exits a room and then re-enters it without reloading the room. r=Mardak
browser/components/loop/content/shared/js/otSdkDriver.js
browser/components/loop/test/shared/otSdkDriver_test.js
--- a/browser/components/loop/content/shared/js/otSdkDriver.js
+++ b/browser/components/loop/content/shared/js/otSdkDriver.js
@@ -33,23 +33,19 @@ loop.OTSdkDriver = (function() {
       if (!options.mozLoop) {
         throw new Error("Missing option mozLoop");
       }
       this.mozLoop = options.mozLoop;
     }
 
     this.connections = {};
 
-    // Metrics object to keep track of the number of connections we have
+    // Setup the metrics object to keep track of the number of connections we have
     // and the amount of streams.
-    this._metrics = {
-      connections: 0,
-      sendStreams: 0,
-      recvStreams: 0
-    };
+    this._resetMetrics();
 
     this.dispatcher.register(this, [
       "setupStreamElements",
       "setMute"
     ]);
 
     // Set loop.debug.twoWayMediaTelemetry to true in the browser
     // by changing the hidden pref loop.debug.twoWayMediaTelemetry using
@@ -104,16 +100,27 @@ loop.OTSdkDriver = (function() {
           // always send on the publisher channel, and receive on the subscriber
           // channel.
           text: {}
         }
       };
     },
 
     /**
+     * Resets the metrics for the driver.
+     */
+    _resetMetrics: function() {
+      this._metrics = {
+        connections: 0,
+        sendStreams: 0,
+        recvStreams: 0
+      };
+    },
+
+    /**
      * Handles the setupStreamElements action. Saves the required data and
      * kicks off the initialising of the publisher.
      *
      * @param {sharedActions.SetupStreamElements} actionData The data associated
      *   with the action. See action.js.
      */
     setupStreamElements: function(actionData) {
       this.publisherConfig = actionData.publisherConfig;
@@ -288,16 +295,19 @@ loop.OTSdkDriver = (function() {
       }
       if (this.publisher) {
         this.publisher.off("accessAllowed accessDenied accessDialogOpened " +
                            "streamCreated streamDestroyed");
         this.publisher.destroy();
         delete this.publisher;
       }
 
+      // Now reset the metrics as well.
+      this._resetMetrics();
+
       this._noteConnectionLengthIfNeeded(this._getTwoWayMediaStartTime(), performance.now());
 
       // Also, tidy these variables ready for next time.
       delete this._sessionConnected;
       delete this._publisherReady;
       delete this._publishedLocalStream;
       delete this._subscribedRemoteStream;
       delete this._mockPublisherEl;
--- a/browser/components/loop/test/shared/otSdkDriver_test.js
+++ b/browser/components/loop/test/shared/otSdkDriver_test.js
@@ -108,16 +108,29 @@ describe("loop.OTSdkDriver", function ()
       }).to.Throw(/dispatcher/);
     });
 
     it("should throw an error if the sdk is missing", function() {
       expect(function() {
         new loop.OTSdkDriver({dispatcher: dispatcher});
       }).to.Throw(/sdk/);
     });
+
+    it("should set the metrics to zero", function() {
+      driver = new loop.OTSdkDriver({
+        dispatcher: dispatcher,
+        sdk: sdk
+      });
+
+      expect(driver._metrics).eql({
+        connections: 0,
+        sendStreams: 0,
+        recvStreams: 0
+      });
+    });
   });
 
   describe("#setupStreamElements", function() {
     it("should call initPublisher", function() {
       driver.setupStreamElements(new sharedActions.SetupStreamElements({
         publisherConfig: publisherConfig
       }));
 
@@ -469,16 +482,32 @@ describe("loop.OTSdkDriver", function ()
         });
       });
 
       driver.disconnectSession();
 
       expect(subscribedEvents).eql([]);
     });
 
+    it("should reset the metrics to zero", function() {
+      driver._metrics = {
+        connections: 1,
+        sendStreams: 2,
+        recvStreams: 3
+      };
+
+      driver.disconnectSession();
+
+      expect(driver._metrics).eql({
+        connections: 0,
+        sendStreams: 0,
+        recvStreams: 0
+      });
+    });
+
     it("should dispatch a DataChannelsAvailable action with available = false", function() {
       driver.disconnectSession();
 
       sinon.assert.called(dispatcher.dispatch);
       sinon.assert.calledWithExactly(dispatcher.dispatch,
         new sharedActions.DataChannelsAvailable({
           available: false
         }));