Bug 1088346 - Handle "answered-elsewhere" on incoming calls for desktop on Loop. r=nperriault

This commit is contained in:
Mark Banner
2014-10-24 14:22:59 +01:00
parent 39805c7af4
commit 3e04dea9e9
3 changed files with 50 additions and 108 deletions

View File

@@ -394,19 +394,25 @@ loop.conversation = (function(mozL10n) {
if (progressData.state !== "terminated")
return;
if (progressData.reason === "cancel" ||
progressData.reason === "closed") {
this._abortIncomingCall();
return;
}
// XXX This would be nicer in the _abortIncomingCall function, but we need to stop
// it here for now due to server-side issues that are being fixed in bug 1088351.
// This is before the abort call to ensure that it happens before the window is
// closed.
navigator.mozLoop.stopAlerting();
if (progressData.reason === "timeout") {
// If we hit any of the termination reasons, and the user hasn't accepted
// then it seems reasonable to close the window/abort the incoming call.
//
// If the user has accepted the call, and something's happened, display
// the call failed view.
//
// https://wiki.mozilla.org/Loop/Architecture/MVP#Termination_Reasons
if (previousState === "init" || previousState === "alerting") {
this._abortIncomingCall();
} else {
this.setState({callFailed: true, callStatus: "end"});
}
}
},
/**
@@ -414,7 +420,6 @@ loop.conversation = (function(mozL10n) {
* closes the websocket.
*/
_abortIncomingCall: function() {
navigator.mozLoop.stopAlerting();
this._websocket.close();
// Having a timeout here lets the logging for the websocket complete and be
// displayed on the console if both are on.

View File

@@ -394,19 +394,25 @@ loop.conversation = (function(mozL10n) {
if (progressData.state !== "terminated")
return;
if (progressData.reason === "cancel" ||
progressData.reason === "closed") {
this._abortIncomingCall();
return;
}
// XXX This would be nicer in the _abortIncomingCall function, but we need to stop
// it here for now due to server-side issues that are being fixed in bug 1088351.
// This is before the abort call to ensure that it happens before the window is
// closed.
navigator.mozLoop.stopAlerting();
if (progressData.reason === "timeout") {
// If we hit any of the termination reasons, and the user hasn't accepted
// then it seems reasonable to close the window/abort the incoming call.
//
// If the user has accepted the call, and something's happened, display
// the call failed view.
//
// https://wiki.mozilla.org/Loop/Architecture/MVP#Termination_Reasons
if (previousState === "init" || previousState === "alerting") {
this._abortIncomingCall();
} else {
this.setState({callFailed: true, callStatus: "end"});
}
}
},
/**
@@ -414,7 +420,6 @@ loop.conversation = (function(mozL10n) {
* closes the websocket.
*/
_abortIncomingCall: function() {
navigator.mozLoop.stopAlerting();
this._websocket.close();
// Having a timeout here lets the logging for the websocket complete and be
// displayed on the console if both are on.

View File

@@ -431,87 +431,7 @@ describe("loop.conversation", function() {
sandbox.stub(window, "close");
});
describe("progress - terminated - cancel", function() {
it("should stop alerting", function(done) {
promise.then(function() {
icView._websocket.trigger("progress", {
state: "terminated",
reason: "cancel"
});
sinon.assert.calledOnce(navigator.mozLoop.stopAlerting);
done();
});
});
it("should close the websocket", function(done) {
promise.then(function() {
icView._websocket.trigger("progress", {
state: "terminated",
reason: "cancel"
});
sinon.assert.calledOnce(icView._websocket.close);
done();
});
});
it("should close the window", function(done) {
promise.then(function() {
icView._websocket.trigger("progress", {
state: "terminated",
reason: "cancel"
});
sandbox.clock.tick(1);
sinon.assert.calledOnce(window.close);
done();
});
});
});
describe("progress - terminated - closed", function() {
it("should stop alerting", function(done) {
promise.then(function() {
icView._websocket.trigger("progress", {
state: "terminated",
reason: "closed"
});
sinon.assert.calledOnce(navigator.mozLoop.stopAlerting);
done();
});
});
it("should close the websocket", function(done) {
promise.then(function() {
icView._websocket.trigger("progress", {
state: "terminated",
reason: "closed"
});
sinon.assert.calledOnce(icView._websocket.close);
done();
});
});
it("should close the window", function(done) {
promise.then(function() {
icView._websocket.trigger("progress", {
state: "terminated",
reason: "closed"
});
sandbox.clock.tick(1);
sinon.assert.calledOnce(window.close);
done();
});
});
});
describe("progress - terminated - timeout (previousState = alerting)", function() {
describe("progress - terminated (previousState = alerting)", function() {
it("should stop alerting", function(done) {
promise.then(function() {
icView._websocket.trigger("progress", {
@@ -528,7 +448,7 @@ describe("loop.conversation", function() {
promise.then(function() {
icView._websocket.trigger("progress", {
state: "terminated",
reason: "timeout"
reason: "closed"
}, "alerting");
sinon.assert.calledOnce(icView._websocket.close);
@@ -540,7 +460,7 @@ describe("loop.conversation", function() {
promise.then(function() {
icView._websocket.trigger("progress", {
state: "terminated",
reason: "timeout"
reason: "answered-elsewhere"
}, "alerting");
sandbox.clock.tick(1);
@@ -551,20 +471,32 @@ describe("loop.conversation", function() {
});
});
describe("progress - terminated - timeout (previousState not init" +
describe("progress - terminated (previousState not init" +
" nor alerting)",
function() {
it("should set the state to end", function(done) {
promise.then(function() {
icView._websocket.trigger("progress", {
state: "terminated",
reason: "timeout"
reason: "media-fail"
}, "connecting");
expect(icView.state.callStatus).eql("end");
done();
});
});
it("should stop alerting", function(done) {
promise.then(function() {
icView._websocket.trigger("progress", {
state: "terminated",
reason: "media-fail"
}, "connecting");
sinon.assert.calledOnce(navigator.mozLoop.stopAlerting);
done();
});
});
});
});
});