Bug 1074517 Second call with a Loop url gets disconnected - ensure stream published/subscribed flags are properly reset. r=dmose a=loop-only
authorMark Banner <standard8@mozilla.com>
Thu, 23 Oct 2014 10:44:13 +0100
changeset 233767 3dc36b88d62338996cc0b24b40f7d62ef52efd54
parent 233766 7203a9983dfc1584899b3947116ddf693f4b9c98
child 233768 358002151c878ed41602770f68faa4a43ae050c6
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdmose, loop-only
bugs1074517
milestone35.0a2
Bug 1074517 Second call with a Loop url gets disconnected - ensure stream published/subscribed flags are properly reset. r=dmose a=loop-only
browser/components/loop/content/shared/js/models.js
browser/components/loop/test/shared/models_test.js
--- a/browser/components/loop/content/shared/js/models.js
+++ b/browser/components/loop/content/shared/js/models.js
@@ -160,16 +160,21 @@ loop.shared.models = (function(l10n) {
 
     /**
      * Starts a SDK session and subscribe to call events.
      */
     startSession: function() {
       if (!this.isSessionReady()) {
         throw new Error("Can't start session as it's not ready");
       }
+      this.set({
+        publishedStream: false,
+        subscribedStream: false
+      });
+
       this.session = this.sdk.initSession(this.get("sessionId"));
       this.listenTo(this.session, "streamCreated", this._streamCreated);
       this.listenTo(this.session, "connectionDestroyed",
                                   this._connectionDestroyed);
       this.listenTo(this.session, "sessionDisconnected",
                                   this._sessionDisconnected);
       this.listenTo(this.session, "networkDisconnected",
                                   this._networkDisconnected);
@@ -177,18 +182,21 @@ loop.shared.models = (function(l10n) {
                            this._onConnectCompletion.bind(this));
     },
 
     /**
      * Ends current session.
      */
     endSession: function() {
       this.session.disconnect();
-      this.set("ongoing", false)
-          .once("session:ended", this.stopListening, this);
+      this.set({
+        publishedStream: false,
+        subscribedStream: false,
+        ongoing: false
+      }).once("session:ended", this.stopListening, this);
     },
 
     /**
      * Helper function to determine if video stream is available for the
      * incoming or outgoing call
      *
      * @param {string} callType Incoming or outgoing call
      */
--- a/browser/components/loop/test/shared/models_test.js
+++ b/browser/components/loop/test/shared/models_test.js
@@ -146,23 +146,32 @@ describe("loop.shared.models", function(
 
       describe("#startSession", function() {
         var model;
 
         beforeEach(function() {
           model = new sharedModels.ConversationModel(fakeSessionData, {
             sdk: fakeSDK
           });
+          model.set({
+            publishedStream: true,
+            subscribedStream: true
+          });
           model.startSession();
         });
 
         it("should start a session", function() {
           sinon.assert.calledOnce(fakeSDK.initSession);
         });
 
+        it("should reset the stream flags", function() {
+          expect(model.get("publishedStream")).eql(false);
+          expect(model.get("subscribedStream")).eql(false);
+        });
+
         it("should call connect", function() {
           fakeSession.connect = sandbox.stub();
 
           model.startSession();
 
           sinon.assert.calledOnce(fakeSession.connect);
           sinon.assert.calledWithExactly(fakeSession.connect,
                         sinon.match.string, sinon.match.string,
@@ -216,17 +225,17 @@ describe("loop.shared.models", function(
                 cb({
                   error: true
                 });
               };
               sandbox.stub(model, "trigger");
 
               model.startSession();
 
-              sinon.assert.calledOnce(model.trigger);
+              sinon.assert.called(model.trigger);
               sinon.assert.calledWithExactly(model.trigger,
                           "session:connection-error", sinon.match.object);
             });
 
           it("should set the connected attr to true on connection completed",
             function() {
               fakeSession.connect = function(key, token, cb) {
                 cb();
@@ -303,16 +312,17 @@ describe("loop.shared.models", function(
 
       describe("#endSession", function() {
         var model;
 
         beforeEach(function() {
           model = new sharedModels.ConversationModel(fakeSessionData, {
             sdk: fakeSDK
           });
+          model.set("ongoing", true);
           model.startSession();
         });
 
         it("should disconnect current session", function() {
           model.endSession();
 
           sinon.assert.calledOnce(fakeSession.disconnect);
         });
@@ -324,16 +334,28 @@ describe("loop.shared.models", function(
         });
 
         it("should set the ongoing attribute to false", function() {
           model.endSession();
 
           expect(model.get("ongoing")).eql(false);
         });
 
+        it("should set the streams to unpublished", function() {
+          model.set({
+            publishedStream: true,
+            subscribedStream: true
+          });
+
+          model.endSession();
+
+          expect(model.get("publishedStream")).eql(false);
+          expect(model.get("subscribedStream")).eql(false);
+        });
+
         it("should stop listening to session events once the session is " +
            "actually disconnected", function() {
             sandbox.stub(model, "stopListening");
 
             model.endSession();
             model.trigger("session:ended");
 
             sinon.assert.calledOnce(model.stopListening);