Skip to content

Commit

Permalink
JsSIP commits through Dec.10 hold/mute, extensive testing and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
James Criscuolo committed Dec 13, 2013
1 parent 1c5a90c commit 8ab99f1
Show file tree
Hide file tree
Showing 18 changed files with 931 additions and 156 deletions.
51 changes: 35 additions & 16 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module.exports = function(grunt) {
'src/Utils.js',
'src/SanityCheck.js',
'src/DigestAuthentication.js',
'src/WebRTC.js'
'src/WebRTC.js',
'src/tail.js'
];

// Project configuration.
Expand All @@ -39,27 +40,24 @@ module.exports = function(grunt) {
* Copyright (c) 2012-<%= grunt.template.today("yyyy") %> José Luis Millán - Versatica <http://www.versatica.com>\n\
* Homepage: http://jssip.net\n\
* License: http://jssip.net/license\n\
*/\n\n\n',
footer: '\
\n\n\nwindow.SIP = SIP;\n\
}(window));\n\n'
*/\n\n\n'
},
concat: {
dist: {
src: srcFiles,
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.js',
options: {
banner: '<%= meta.banner %>',
separator: '\n\n\n',
footer: '<%= meta.footer %>',
separator: '\n\n',
process: true
},
nonull: true
},
post_dist: {
src: [
'dist/<%= pkg.name %>-<%= pkg.version %>.js',
'src/Grammar/dist/Grammar.js'
'src/Grammar/dist/Grammar.js',
'src/SDP/dist/SDP.js'
],
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.js',
nonull: true
Expand All @@ -69,16 +67,16 @@ module.exports = function(grunt) {
dest: 'dist/<%= pkg.name %>-devel.js',
options: {
banner: '<%= meta.banner %>',
separator: '\n\n\n',
footer: '<%= meta.footer %>',
separator: '\n\n',
process: true
},
nonull: true
},
post_devel: {
src: [
'dist/<%= pkg.name %>-devel.js',
'src/Grammar/dist/Grammar.js'
'src/Grammar/dist/Grammar.js',
'src/SDP/dist/SDP.js'
],
dest: 'dist/<%= pkg.name %>-devel.js',
nonull: true
Expand Down Expand Up @@ -111,11 +109,14 @@ module.exports = function(grunt) {
undef: true,
boss: true,
eqnull: true,
onecase:true,
unused:true,
supernew: true
},
globals: {}
onecase: true,
unused: true,
supernew: true,
globals: {
module: true,
define: true
}
}
},
uglify: {
dist: {
Expand Down Expand Up @@ -169,6 +170,24 @@ module.exports = function(grunt) {
});
});

// Task for building JsSIP SDP.js and SDP.min.js files.
grunt.registerTask('sdp', function(){
var done = this.async(); // This is an async task.
var sys = require('sys');
var exec = require('child_process').exec;
var child;

// Build a bundle of 'sdp-transform' for the browser.
console.log('"sdp" task: getting JsSIP parser from "sdp-transform" ...');
child = exec('browserify src/SDP/main.js -o src/SDP/dist/SDP.js', function(error, stdout, stderr) {
if (error) {
sys.print('ERROR: ' + stderr);
done(false); // Tell grunt that async task has failed.
}
console.log('OK');
done(); // Tell grunt that async task has succeeded.
});
});

// Task for building jssip-devel.js (uncompressed), jssip-X.Y.Z.js (uncompressed)
// and jssip-X.Y.Z.min.js (minified).
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"grunt-contrib-jshint": "~0.3.0",
"grunt-contrib-qunit": "~0.2.0",
"pegjs": "0.7.0",
"node-minify": "~0.7.2"
"node-minify": "~0.7.2",
"browserify": "~2.36.0",
"sdp-transform": "~0.3.3"
},
"engines": {
"node": ">=0.8"
Expand Down
1 change: 1 addition & 0 deletions src/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ SIP.C= {

// SIP scheme
SIP: 'sip',
SIPS: 'sips',

// End and Failure causes
causes: {
Expand Down
18 changes: 16 additions & 2 deletions src/Dialog/RequestSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,22 @@ RequestSender = function(dialog, applicant, request) {

RequestSender.prototype = {
send: function() {
var request_sender = new SIP.RequestSender(this, this.dialog.owner.ua);
request_sender.send();
var self = this,
request_sender = new SIP.RequestSender(this, this.dialog.owner.ua);

request_sender.send();

// RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-
if (this.request.method === SIP.C.INVITE && request_sender.clientTransaction.state !== SIP.Transactions.C.STATUS_TERMINATED) {
this.dialog.uac_pending_reply = true;
request_sender.clientTransaction.on('stateChanged', function(e){
if (e.sender.state === SIP.Transactions.C.STATUS_ACCEPTED ||
e.sender.state === SIP.Transactions.C.STATUS_COMPLETED ||
e.sender.state === SIP.Transactions.C.STATUS_TERMINATED) {
self.dialog.uac_pending_reply = false;
}
});
}
},

onRequestTimeout: function() {
Expand Down
46 changes: 30 additions & 16 deletions src/Dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ var Dialog,
Dialog = function(owner, message, type, state) {
var contact;

this.uac_pending_reply = false;
this.uas_pending_reply = false;

if(!message.hasHeader('contact')) {
return {
error: 'unable to create a Dialog without Contact header field'
Expand Down Expand Up @@ -154,9 +157,11 @@ Dialog.prototype = {

// RFC 3261 12.2.2
checkInDialogRequest: function(request) {
var self = this;

if(!this.remote_seqnum) {
this.remote_seqnum = request.cseq;
} else if(request.method !== SIP.C.INVITE && request.cseq < this.remote_seqnum) {
} else if(request.cseq < this.remote_seqnum) {
//Do not try to reply to an ACK request.
if (request.method !== SIP.C.ACK) {
request.reply(500);
Expand All @@ -172,29 +177,38 @@ Dialog.prototype = {
switch(request.method) {
// RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-
case SIP.C.INVITE:
if(request.cseq < this.remote_seqnum) {
if(this.state === C.STATUS_EARLY) {
var retryAfter = (Math.random() * 10 | 0) + 1;
request.reply(500, null, ['Retry-After:'+ retryAfter]);
} else {
request.reply(500);
}
return false;
}
// RFC3261 14.2
if(this.state === C.STATUS_EARLY) {
if (this.uac_pending_reply === true) {
request.reply(491);
} else if (this.uas_pending_reply === true) {
return false;
} else {
this.uas_pending_reply = true;
request.server_transaction.on('stateChanged', function(e){
if (e.sender.state === SIP.Transactions.C.STATUS_ACCEPTED ||
e.sender.state === SIP.Transactions.C.STATUS_COMPLETED ||
e.sender.state === SIP.Transactions.C.STATUS_TERMINATED) {
self.uas_pending_reply = false;
}
});
}
// RFC3261 12.2.2 Replace the dialog`s remote target URI

// RFC3261 12.2.2 Replace the dialog`s remote target URI if the request is accepted
if(request.hasHeader('contact')) {
this.remote_target = request.parseHeader('contact').uri;
request.server_transaction.on('stateChanged', function(e){
if (e.sender.state === SIP.Transactions.C.STATUS_ACCEPTED) {
self.remote_target = request.parseHeader('contact').uri;
}
});
}
break;
case SIP.C.NOTIFY:
// RFC6655 3.2 Replace the dialog`s remote target URI
// RFC6655 3.2 Replace the dialog`s remote target URI if the request is accepted
if(request.hasHeader('contact')) {
this.remote_target = request.parseHeader('contact').uri;
request.server_transaction.on('stateChanged', function(e){
if (e.sender.state === SIP.Transactions.C.STATUS_COMPLETED) {
self.remote_target = request.parseHeader('contact').uri;
}
});
}
break;
}
Expand Down
11 changes: 11 additions & 0 deletions src/Exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Exceptions= {
this.code = 2;
this.name = 'INVALID_STATE_ERROR';
this.status = status;
this.message = 'Invalid status: ' + status;
};
exception.prototype = new Error();
return exception;
Expand All @@ -40,6 +41,16 @@ Exceptions= {
};
exception.prototype = new Error();
return exception;
}()),

NotReadyError: (function(){
var exception = function(message) {
this.code = 4;
this.name = 'NOT_READY_ERROR';
this.message = message;
};
exception.prototype = new Error();
return exception;
}())
};

Expand Down
Loading

0 comments on commit 8ab99f1

Please sign in to comment.