Bug 972017 Part 2 - Set up actions and a dispatcher and start to handle obtaining call data for outgoing Loop calls from the desktop client. r=mikedeboer
This commit is contained in:
@@ -15,6 +15,12 @@ loop.Client = (function($) {
|
||||
// The expected properties to be returned from the GET /calls request.
|
||||
var expectedCallProperties = ["calls"];
|
||||
|
||||
// THe expected properties to be returned from the POST /calls request.
|
||||
var expectedPostCallProperties = [
|
||||
"apiKey", "callId", "progressURL",
|
||||
"sessionId", "sessionToken", "websocketToken"
|
||||
];
|
||||
|
||||
/**
|
||||
* Loop server client.
|
||||
*
|
||||
@@ -209,6 +215,44 @@ loop.Client = (function($) {
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets up an outgoing call, getting the relevant data from the server.
|
||||
*
|
||||
* Callback parameters:
|
||||
* - err null on successful registration, non-null otherwise.
|
||||
* - result an object of the obtained data for starting the call, if successful
|
||||
*
|
||||
* @param {Array} calleeIds an array of emails and phone numbers.
|
||||
* @param {String} callType the type of call.
|
||||
* @param {Function} cb Callback(err, result)
|
||||
*/
|
||||
setupOutgoingCall: function(calleeIds, callType, cb) {
|
||||
this.mozLoop.hawkRequest(this.mozLoop.LOOP_SESSION_TYPE.FXA,
|
||||
"/calls", "POST", {
|
||||
calleeId: calleeIds,
|
||||
callType: callType
|
||||
},
|
||||
function (err, responseText) {
|
||||
if (err) {
|
||||
this._failureHandler(cb, err);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var postData = JSON.parse(responseText);
|
||||
|
||||
var outgoingCallData = this._validate(postData,
|
||||
expectedPostCallProperties);
|
||||
|
||||
cb(null, outgoingCallData);
|
||||
} catch (err) {
|
||||
console.log("Error requesting call info", err);
|
||||
cb(err);
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a value to a telemetry histogram, ignoring errors.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user