Skip to content

Commit

Permalink
Merge branch 'issue1' into github
Browse files Browse the repository at this point in the history
Also fix related Session.js logic, testing

Conflicts:
	src/Session.js
  • Loading branch information
joseph-onsip committed May 9, 2014
2 parents 3413127 + 722765b commit 44f543c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,20 +634,24 @@ Session.prototype = {
reg_tone = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,
reg_duration = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;

if (contentType && (contentType.match(/^application\/dtmf-relay/i))) {
if (request.body) {
body = request.body.split('\r\n');
if (body.length === 2) {
if (reg_tone.test(body[0])) {
tone = body[0].replace(reg_tone,"$2");
}
if (reg_duration.test(body[1])) {
duration = parseInt(body[1].replace(reg_duration,"$2"), 10);
if (contentType) {
if (contentType.match(/^application\/dtmf-relay/i)) {
if (request.body) {
body = request.body.split('\r\n', 2);
if (body.length === 2) {
if (reg_tone.test(body[0])) {
tone = body[0].replace(reg_tone,"$2");
}
if (reg_duration.test(body[1])) {
duration = parseInt(body[1].replace(reg_duration,"$2"), 10);
}
}
}
}

new DTMF(this, tone, {duration: duration}).init_incoming(request);
new DTMF(this, tone, {duration: duration}).init_incoming(request);
} else {
request.reply(415, null, ["Accept: application/dtmf-relay"]);
}
}
}
break;
Expand Down
19 changes: 18 additions & 1 deletion test/spec/SpecSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -1462,14 +1462,31 @@ describe('InviteServerContext', function() {
describe('method is INFO', function() {
it('makes a new DTMF', function() {
InviteServerContext.status = 12;
req = SIP.Parser.parseMessage('INFO sip:gled5gsn@hk95bautgaa7.invalid;transport=ws;aor=james%40onsnip.onsip.com SIP/2.0\r\nMax-Forwards: 65\r\nTo: <sip:james@onsnip.onsip.com>\r\nFrom: "test1" <sip:test1@onsnip.onsip.com>;tag=rto5ib4052\r\nCall-ID: grj0liun879lfj35evfq\r\nCSeq: 1798 INVITE\r\nContact: <sip:e55r35u3@kgu78r4e1e6j.invalid;transport=ws;ob>\r\nAllow: ACK,CANCEL,BYE,OPTIONS,INVITE,MESSAGE\r\nContent-Type: application/json\r\nSupported: outbound\r\nUser-Agent: SIP.js 0.5.0-devel\r\nContent-Length: 11\r\n\r\na=sendrecv\r\n', InviteServerContext.ua);
req = SIP.Parser.parseMessage('INFO sip:gled5gsn@hk95bautgaa7.invalid;transport=ws;aor=james%40onsnip.onsip.com SIP/2.0\r\nMax-Forwards: 65\r\nTo: <sip:james@onsnip.onsip.com>\r\nFrom: "test1" <sip:test1@onsnip.onsip.com>;tag=rto5ib4052\r\nCall-ID: grj0liun879lfj35evfq\r\nCSeq: 1798 INVITE\r\nContact: <sip:e55r35u3@kgu78r4e1e6j.invalid;transport=ws;ob>\r\nAllow: ACK,CANCEL,BYE,OPTIONS,INVITE,MESSAGE\r\nContent-Type: application/dtmf-relay\r\nSupported: outbound\r\nUser-Agent: SIP.js 0.5.0-devel\r\nContent-Length: 26\r\n\r\nSignal= 6\r\nDuration= 100\r\n', InviteServerContext.ua);

InviteServerContext.dialog = new SIP.Dialog(InviteServerContext, req, 'UAS');

spyOn(req, 'reply');

InviteServerContext.receiveRequest(req);

expect(req.reply).toHaveBeenCalledWith(200);

//Not sure how to test this... another Session/* problem
});

it('returns a 415 if DTMF packet had the wrong content-type header', function() {
InviteServerContext.status = 12;
req = SIP.Parser.parseMessage('INFO sip:gled5gsn@hk95bautgaa7.invalid;transport=ws;aor=james%40onsnip.onsip.com SIP/2.0\r\nMax-Forwards: 65\r\nTo: <sip:james@onsnip.onsip.com>\r\nFrom: "test1" <sip:test1@onsnip.onsip.com>;tag=rto5ib4052\r\nCall-ID: grj0liun879lfj35evfq\r\nCSeq: 1798 INVITE\r\nContact: <sip:e55r35u3@kgu78r4e1e6j.invalid;transport=ws;ob>\r\nAllow: ACK,CANCEL,BYE,OPTIONS,INVITE,MESSAGE\r\nContent-Type: application/json\r\nSupported: outbound\r\nUser-Agent: SIP.js 0.5.0-devel\r\nContent-Length: 11\r\n\r\na=sendrecv\r\n', InviteServerContext.ua);

InviteServerContext.dialog = new SIP.Dialog(InviteServerContext, req, 'UAS');

spyOn(req, 'reply');

InviteServerContext.receiveRequest(req);

expect(req.reply).toHaveBeenCalledWith(415, null, ["Accept: application/dtmf-relay"]);
});
});

describe('method is REFER', function() {
Expand Down

0 comments on commit 44f543c

Please sign in to comment.