Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #124 from mozilla-services/Bug1025779
Browse files Browse the repository at this point in the history
Bug1025779 — Pass the calleId / Friendlyname in the call-token creation and upon retrieval.
  • Loading branch information
almet committed Jun 27, 2014
2 parents 98ff56e + 0fcd0dc commit 078f422
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
40 changes: 30 additions & 10 deletions loop/index.js
Expand Up @@ -212,22 +212,31 @@ function authenticate(req, res, next) {

/**
* Helper to store and trigger an user initiated call.
*
* options is a javascript object which can have the following keys:
* - user: the identifier of the connected user.
* - callerId: the identifier for the caller.
* - urls: the list of simple push urls to notify of the new call.
* - calleeFriendlyName: the friendly name of the person called.
* - callToken: the call token that was used to initiate the call (if any)
*/
function returnUserCallTokens(user, callerId, urls, callToken, res) {
function returnUserCallTokens(options, res) {
tokBox.getSessionTokens(function(err, tokboxInfo) {
if (res.serverError(err)) return;

var urls = options.urls;
var currentTimestamp = Date.now();
var callId = crypto.randomBytes(16).toString('hex');

storage.addUserCall(user, {
'callerId': callerId,
storage.addUserCall(options.user, {
'callerId': options.callerId,
'calleeFriendlyName': options.calleeFriendlyName,
'callId': callId,
'userMac': user,
'userMac': options.user,
'sessionId': tokboxInfo.sessionId,
'calleeToken': tokboxInfo.calleeToken,
'timestamp': currentTimestamp,
'callToken': callToken
'callToken': options.callToken
}, function(err, record){
if (res.serverError(err)) return;

Expand Down Expand Up @@ -445,6 +454,7 @@ app.post('/call-url', requireHawkSession, requireParams('callerId'),
var tokenPayload = {
user: req.user,
uuid: uuid,
issuer: req.body.issuer || '',
callerId: req.body.callerId
};
if (expiresIn !== undefined) {
Expand Down Expand Up @@ -481,6 +491,7 @@ app.get("/calls", requireHawkSession, function(req, res) {
}).map(function(record) {
return {
callId: record.callId,
calleeId: record.calleeFriendlyName,
apiKey: tokBox.apiKey,
sessionId: record.sessionId,
sessionToken: record.calleeToken,
Expand All @@ -501,8 +512,13 @@ app.post('/calls', requireHawkSession, requireParams('calleeId'),
function callUser(callee) {
return function() {
// TODO: set caller ID. Bug 1025894.
returnUserCallTokens(callee, undefined, callees[callee], undefined,
res);
returnUserCallTokens({
user: callee,
callerId: undefined,
urls: callees[callee],
callToken: undefined,
calleeFriendlyName: undefined
}, res);
}();
}

Expand Down Expand Up @@ -578,9 +594,13 @@ app.post('/calls/:token', validateToken, function(req, res) {
res.json(410, 'Gone');
return;
}

returnUserCallTokens(req.token.user, req.token.callerId, urls,
req.param('token'), res);
returnUserCallTokens({
user: req.token.user,
callerId: req.token.callerId,
urls: urls,
callToken: req.param('token'),
calleeFriendlyName: req.token.issuer
}, res);
});
});

Expand Down
25 changes: 15 additions & 10 deletions test/index_test.js
Expand Up @@ -361,13 +361,13 @@ describe("index.js", function() {
var sandbox;

app.post('/returnUserCallTokens', function(req, res) {
returnUserCallTokens(
req.body.callee,
req.body.callerId,
req.body.urls,
req.body.callToken,
res
);
returnUserCallTokens({
user: req.body.callee,
callerId: req.body.callerId,
urls: req.body.urls,
calleeFriendlyName: req.body.calleeFriendlyName,
callToken: req.body.callToken
}, res);
});

beforeEach(function() {
Expand All @@ -394,6 +394,7 @@ describe("index.js", function() {

var user = "user@arandomuri";
var callerId = "aCallerId";
var calleeFriendlyName = "issuerName";
var urls = ["url1", "url2"];
var callToken = 'call-token';
var tokBoxSessionId = "aTokboxSession";
Expand All @@ -418,7 +419,8 @@ describe("index.js", function() {
callee: user,
callerId: callerId,
urls: urls,
callToken: callToken
callToken: callToken,
calleeFriendlyName: calleeFriendlyName
})
.expect(200)
.end(function(err, res) {
Expand All @@ -438,7 +440,8 @@ describe("index.js", function() {
callee: user,
callerId: callerId,
urls: urls,
callToken: callToken
callToken: callToken,
calleeFriendlyName: calleeFriendlyName
})
.expect(200)
.end(function(err, res) {
Expand Down Expand Up @@ -466,7 +469,8 @@ describe("index.js", function() {
callee: user,
callerId: callerId,
urls: urls,
callToken: callToken
callToken: callToken,
calleeFriendlyName: calleeFriendlyName
})
.expect(200)
.end(function(err, res) {
Expand All @@ -479,6 +483,7 @@ describe("index.js", function() {
delete items[0].timestamp;
expect(items[0]).eql({
callerId: callerId,
calleeFriendlyName: calleeFriendlyName,
userMac: user,
sessionId: tokBoxSessionId,
calleeToken: tokBoxCalleeToken,
Expand Down

0 comments on commit 078f422

Please sign in to comment.