Bug 1227539: Part 2 - implement the new HangupNow action on standalone too so that leaving a room will still work. r=Standard8
☠☠ backed out by b92cd30cf34f ☠ ☠
authorMike de Boer <mdeboer@mozilla.com>
Wed, 23 Dec 2015 13:37:59 +0100
changeset 317404 30b9e8aa695d29d815baa2b1f8c05ff2fa10df6a
parent 317403 860d77fbf406524dd7ad67066d92e051e9555fba
child 317405 869deb5491192921298b0a1edc0ab3fc17502648
push id8691
push userbmo:vivekb.balakrishnan@gmail.com
push dateWed, 23 Dec 2015 21:07:27 +0000
reviewersStandard8
bugs1227539
milestone46.0a1
Bug 1227539: Part 2 - implement the new HangupNow action on standalone too so that leaving a room will still work. r=Standard8
browser/extensions/loop/content/modules/MozLoopAPI.jsm
browser/extensions/loop/content/shared/js/activeRoomStore.js
browser/extensions/loop/standalone/content/js/standaloneMozLoop.js
browser/extensions/loop/test/shared/activeRoomStore_test.js
browser/extensions/loop/test/standalone/standaloneMozLoop_test.js
--- a/browser/extensions/loop/content/modules/MozLoopAPI.jsm
+++ b/browser/extensions/loop/content/modules/MozLoopAPI.jsm
@@ -716,17 +716,20 @@ const kMessageHandlers = {
    *                             {String} roomToken The token of the room to leave
    *                             {Number} windowId  The window ID of the chat window
    *                           ]
    * @param {Function} reply   Callback function, invoked with the result of this
    *                           message handler. The result will be sent back to
    *                           the senders' channel.
    */
   HangupNow: function(message, reply) {
-    let [roomToken, windowId] = message.data;
+    let [roomToken, sessionToken, windowId] = message.data;
+    if (!windowId) {
+      windowId = sessionToken;
+    }
 
     LoopRooms.leave(roomToken);
     MozLoopService.setScreenShareState(windowId, false);
     LoopAPI.sendMessageToHandler({
       name: "RemoveBrowserSharingListener",
       data: [windowId]
     });
     reply();
--- a/browser/extensions/loop/content/shared/js/activeRoomStore.js
+++ b/browser/extensions/loop/content/shared/js/activeRoomStore.js
@@ -1139,19 +1139,19 @@ loop.store.ActiveRoomStore = (function()
         clearTimeout(this._timeout);
         delete this._timeout;
       }
 
       // If we're not going to close the window, we can hangup the call ourselves.
       // NOTE: when the window _is_ closed, hanging up the call is performed by
       //       MozLoopService, because we can't get a message across to LoopAPI
       //       in time whilst a window is closing.
-      if (nextState === ROOM_STATES.FAILED && !failedJoinRequest) {
+      if ((nextState === ROOM_STATES.FAILED || !this._isDesktop) && !failedJoinRequest) {
         loop.request("HangupNow", this._storeState.roomToken,
-          this._storeState.windowId);
+          this._storeState.sessionToken, this._storeState.windowId);
       }
 
       this.setStoreState({ roomState: nextState });
     },
 
     /**
      * When feedback is complete, we go back to the ready state, rather than
      * init or gather, as we don't need to get the data from the server again.
--- a/browser/extensions/loop/standalone/content/js/standaloneMozLoop.js
+++ b/browser/extensions/loop/standalone/content/js/standaloneMozLoop.js
@@ -250,16 +250,23 @@ loop.StandaloneMozLoop = (function(mozL1
         if (error) {
           console.error(error);
         }
       });
     }
   };
 
   var kMessageHandlers = {
+    AddConversationContext: function() {},
+    HangupNow: function(data, reply) {
+      var roomToken = data[0];
+      var sessionToken = data[1];
+      StandaloneLoopRooms.leave(roomToken, sessionToken, reply);
+    },
+
     "Rooms:*": function(action, data, reply) {
       var funcName = action.split(":").pop();
       funcName = funcName.charAt(0).toLowerCase() + funcName.substr(1);
 
       if (funcName === PUSH_SUBSCRIPTION) {
         return;
       }
 
--- a/browser/extensions/loop/test/shared/activeRoomStore_test.js
+++ b/browser/extensions/loop/test/shared/activeRoomStore_test.js
@@ -219,17 +219,17 @@ describe("loop.store.ActiveRoomStore", f
     it("should call 'HangupNow' Loop API", function() {
       store.roomFailure(new sharedActions.RoomFailure({
         error: fakeError,
         failedJoinRequest: false
       }));
 
       sinon.assert.calledOnce(requestStubs["HangupNow"]);
       sinon.assert.calledWithExactly(requestStubs["HangupNow"],
-        "fakeToken", "42");
+        "fakeToken", "1627384950", "42");
     });
 
     it("should not call 'HangupNow' Loop API if failedJoinRequest is true", function() {
       store.roomFailure(new sharedActions.RoomFailure({
         error: fakeError,
         failedJoinRequest: true
       }));
 
@@ -1243,17 +1243,17 @@ describe("loop.store.ActiveRoomStore", f
       sinon.assert.calledOnce(clearTimeout);
     });
 
     it("should call 'HangupNow' Loop API", function() {
       store.connectionFailure(connectionFailureAction);
 
       sinon.assert.calledOnce(requestStubs["HangupNow"]);
       sinon.assert.calledWithExactly(requestStubs["HangupNow"],
-        "fakeToken", "42");
+        "fakeToken", "1627384950", "42");
     });
 
     it("should remove the sharing listener", function() {
       sandbox.stub(loop, "unsubscribe");
 
       // Setup the listener.
       store.startBrowserShare(new sharedActions.StartBrowserShare());
 
@@ -1802,29 +1802,33 @@ describe("loop.store.ActiveRoomStore", f
       sandbox.stub(window, "clearTimeout");
       store._timeout = {};
 
       store.windowUnload();
 
       sinon.assert.calledOnce(clearTimeout);
     });
 
-    it("should not call 'HangupNow' Loop API", function() {
+    it("should call 'HangupNow' Loop API", function() {
       store.windowUnload();
 
-      sinon.assert.notCalled(requestStubs["HangupNow"]);
+      sinon.assert.calledOnce(requestStubs["HangupNow"]);
+      sinon.assert.calledWith(requestStubs["HangupNow"], "fakeToken",
+        "1627384950", "1234");
     });
 
-    it("should call not call 'HangupNow' Loop API if the room state is JOINING",
+    it("should call 'HangupNow' Loop API if the room state is JOINING",
       function() {
         store.setStoreState({ roomState: ROOM_STATES.JOINING });
 
         store.windowUnload();
 
-        sinon.assert.notCalled(requestStubs["HangupNow"]);
+        sinon.assert.calledOnce(requestStubs["HangupNow"]);
+        sinon.assert.calledWith(requestStubs["HangupNow"], "fakeToken",
+          "1627384950", "1234");
       });
 
     it("should remove the sharing listener", function() {
       sandbox.stub(loop, "unsubscribe");
 
       // Setup the listener.
       store.startBrowserShare(new sharedActions.StartBrowserShare());
 
@@ -1867,17 +1871,26 @@ describe("loop.store.ActiveRoomStore", f
       sandbox.stub(window, "clearTimeout");
       store._timeout = {};
 
       store.leaveRoom();
 
       sinon.assert.calledOnce(clearTimeout);
     });
 
-    it("should not call 'HangupNow' Loop API", function() {
+    it("should call 'HangupNow' Loop API", function() {
+      store.leaveRoom();
+
+      sinon.assert.calledOnce(requestStubs["HangupNow"]);
+      sinon.assert.calledWith(requestStubs["HangupNow"], "fakeToken", "1627384950");
+    });
+
+    it("should not call 'HangupNow' Loop API when _isDesktop is true", function() {
+      store._isDesktop = true;
+
       store.leaveRoom();
 
       sinon.assert.notCalled(requestStubs["HangupNow"]);
     });
 
     it("should remove the sharing listener", function() {
       sandbox.stub(loop, "unsubscribe");
 
--- a/browser/extensions/loop/test/standalone/standaloneMozLoop_test.js
+++ b/browser/extensions/loop/test/standalone/standaloneMozLoop_test.js
@@ -40,16 +40,32 @@ describe("loop.StandaloneMozLoop", funct
   describe("#constructor", function() {
     it("should require a baseServerUrl setting", function() {
       expect(function() {
         new loop.StandaloneMozLoop();
       }).to.Throw(Error, /required/);
     });
   });
 
+  describe("#hangupNow", function() {
+    it("should call rooms.leave", function() {
+      loop.request("HangupNow", "fakeToken", "fakeSessionToken");
+
+      expect(requests).to.have.length.of(1);
+      expect(requests[0].async).eql(false);
+      expect(requests[0].url).eql(fakeBaseServerUrl + "/rooms/fakeToken");
+      expect(requests[0].method).eql("POST");
+      expect(requests[0].requestHeaders.Authorization)
+        .eql("Basic " + btoa("fakeSessionToken"));
+
+      var requestData = JSON.parse(requests[0].requestBody);
+      expect(requestData.action).eql("leave");
+    });
+  });
+
   describe("#setLoopPref", function() {
     afterEach(function() {
       localStorage.removeItem("fakePref");
     });
 
     it("should store the value of the preference", function() {
       loop.request("SetLoopPref", "fakePref", "fakeValue");