Bug 1227539: Part 2 - implement the new HangupNow action on standalone too so that leaving a room will still work. r=Standard8

This commit is contained in:
Mike de Boer 2015-12-23 13:37:59 +01:00
parent dbb224d42d
commit c2b51485b8
5 changed files with 49 additions and 10 deletions

View File

@ -721,7 +721,10 @@ const kMessageHandlers = {
* 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);

View File

@ -1144,9 +1144,9 @@ loop.store.ActiveRoomStore = (function() {
// 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 });

View File

@ -255,6 +255,13 @@ loop.StandaloneMozLoop = (function(mozL10n) {
};
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);

View File

@ -224,7 +224,7 @@ describe("loop.store.ActiveRoomStore", function() {
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() {
@ -1248,7 +1248,7 @@ describe("loop.store.ActiveRoomStore", function() {
sinon.assert.calledOnce(requestStubs["HangupNow"]);
sinon.assert.calledWithExactly(requestStubs["HangupNow"],
"fakeToken", "42");
"fakeToken", "1627384950", "42");
});
it("should remove the sharing listener", function() {
@ -1807,19 +1807,23 @@ describe("loop.store.ActiveRoomStore", function() {
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() {
@ -1872,7 +1876,16 @@ describe("loop.store.ActiveRoomStore", function() {
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"]);

View File

@ -45,6 +45,22 @@ describe("loop.StandaloneMozLoop", function() {
});
});
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");