Bug 1022594 Part 2. Desktop client needs ability to decline an incoming call - set up a basic websocket protocol and use for both desktop and standalone UI. r=dmose

This commit is contained in:
Mark Banner
2014-08-15 22:54:29 +01:00
parent c8112af356
commit 657c4ada6f
17 changed files with 957 additions and 64 deletions

View File

@@ -189,21 +189,41 @@ loop.conversation = (function(OT, mozL10n) {
if (err) {
console.error("Failed to get the sessionData", err);
// XXX Not the ideal response, but bug 1047410 will be replacing
//this by better "call failed" UI.
// this by better "call failed" UI.
this._notifier.errorL10n("cannot_start_call_session_not_ready");
return;
}
// XXX For incoming calls we might have more than one call queued.
// For now, we'll just assume the first call is the right information.
// We'll probably really want to be getting this data from the
// background worker on the desktop client.
// Bug 1032700 should fix this.
this._conversation.setIncomingSessionData(sessionData[0]);
this._setupWebSocketAndCallView();
});
},
/**
* Used to set up the web socket connection and navigate to the
* call view if appropriate.
*/
_setupWebSocketAndCallView: function() {
this._websocket = new loop.CallConnectionWebSocket({
url: this._conversation.get("progressURL"),
websocketToken: this._conversation.get("websocketToken"),
callId: this._conversation.get("callId"),
});
this._websocket.promiseConnect().then(function() {
this.loadReactComponent(loop.conversation.IncomingCallView({
model: this._conversation,
video: {enabled: this._conversation.hasVideoStream("incoming")}
}));
});
}.bind(this), function() {
this._handleSessionError();
return;
}.bind(this));
},
/**
@@ -214,13 +234,25 @@ loop.conversation = (function(OT, mozL10n) {
this._conversation.incoming();
},
/**
* Declines a call and handles closing of the window.
*/
_declineCall: function() {
this._websocket.decline();
// XXX Don't close the window straight away, but let any sends happen
// first. Ideally we'd wait to close the window until after we have a
// response from the server, to know that everything has completed
// successfully. However, that's quite difficult to ensure at the
// moment so we'll add it later.
setTimeout(window.close, 0);
},
/**
* Declines an incoming call.
*/
decline: function() {
navigator.mozLoop.stopAlerting();
// XXX For now, we just close the window
window.close();
this._declineCall();
},
/**
@@ -238,7 +270,7 @@ loop.conversation = (function(OT, mozL10n) {
// (bug 1048909).
console.log(error);
});
window.close();
this._declineCall();
},
/**
@@ -249,7 +281,7 @@ loop.conversation = (function(OT, mozL10n) {
if (!this._conversation.isSessionReady()) {
console.error("Error: navigated to conversation route without " +
"the start route to initialise the call first");
this._notifier.errorL10n("cannot_start_call_session_not_ready");
this._handleSessionError();
return;
}
@@ -264,6 +296,15 @@ loop.conversation = (function(OT, mozL10n) {
}));
},
/**
* Handles a error starting the session
*/
_handleSessionError: function() {
// XXX Not the ideal response, but bug 1047410 will be replacing
// this by better "call failed" UI.
this._notifier.errorL10n("cannot_start_call_session_not_ready");
},
/**
* Call has ended, display a feedback form.
*/