Skip to content
Permalink
Browse files

Refactored Session

Use the request call_id property

Fix typo

Put MediaSession into Session

Delete Session 'connecting' and Message 'sending' redundant events

Add custom empty 'data' object to Message

Rename Session by RTCSession and MediaSession by RTCMediaHandler

Update the RTCSession LOG_PREFIX

Add dialog error handling

Renamed Session.js by RTCSession.js

Delete redundant line

Add some extra comments

Do not delegate on Dialog the firing of the Session 'failed' event on Dialog error

SIP message originating a 'failure' event in RTCSession can be a request or a response. Changed event data 'request' property by 'message'

Do not RTCSession 'failed' event before firing UA 'newRTCSession' event

Code clean.

- Put RTCSession.sendInitialRequest logic into RTCsession.connect
- Clean code in RTCSession.receiveResponse

Put RTCSession cancel and reject logic into terminate method

Put RTCSession createEarlyDialog and createConfirmedDialog logic into a single createDialog method

Delete RTCSession terminateEarlyDialogs and terminateConfirmedDialog methods.

- Insert logic in RTCSession.close method

Move the logic of RTCSession timers to the corresponding place in the code...

 ... instead of defining a separate function for each timer logic
 - Also put all RTCSession timers into a new RTCSession.timers object. Thanks @saghul

Enhance RTCSession.RequestSender class

Fix some typos

Take out RTCSession internal classes from RTCSession.js file

- Make use of grunt-include-replace npm (grunt upgrade to 0.4 was required)
- Add internal classes into src/RTCSession/ directory

Fix typo
  • Loading branch information
jmillan committed Mar 1, 2013
1 parent e1dd5d8 commit 940fb349d08ddaaafcd97696e5e39bedbc2e02a4
Showing with 1,619 additions and 1,630 deletions.
  1. +38 −17 grunt.js → Gruntfile.js
  2. +1 −1 package.json
  3. +2 −0 src/Constants.js
  4. +22 −25 src/Dialogs.js
  5. +0 −223 src/MediaSession.js
  6. +4 −13 src/Message.js
  7. +1,067 −0 src/RTCSession.js
  8. +197 −0 src/RTCSession/DTMF.js
  9. +214 −0 src/RTCSession/RTCMediaHandler.js
  10. +70 −0 src/RTCSession/RequestSender.js
  11. +0 −1,347 src/Session.js
  12. +4 −4 src/UA.js
@@ -18,8 +18,7 @@ module.exports = function(grunt) {
'src/RequestSender.js',
'src/InDialogRequestSender.js',
'src/Registrator.js',
'src/Session.js',
'src/MediaSession.js',
'src/RTCSession.js',
'src/Message.js',
'src/UA.js',
'src/Utils.js',
@@ -31,14 +30,10 @@ module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
pkg: '<json:package.json>',
pkg: grunt.file.readJSON('package.json'),
meta: {
banner: '/*! jsSIP v@<%= pkg.version %> jssip.net | jssip.net/license */'
},
lint: {
dist: 'dist/<%= pkg.name %>-<%= pkg.version %>.js',
devel: 'dist/<%= pkg.name %>-devel.js'
},
concat: {
dist: {
src: srcFiles,
@@ -55,7 +50,7 @@ module.exports = function(grunt) {
],
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.js'
},
post_min: {
post_uglify: {
src: [
'dist/<%= pkg.name %>-<%= pkg.version %>.min.js',
'src/Grammar/dist/Grammar.min.js'
@@ -70,17 +65,23 @@ module.exports = function(grunt) {
dest: 'dist/<%= pkg.name %>-devel.js'
}
},
min: {
uglify: {
dist: {
src: ['<banner:meta.banner>', '<config:concat.dist.dest>'],
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.min.js'
files: {
'dist/<%= pkg.name %>-<%= pkg.version %>.min.js': ['dist/<%= pkg.name %>-<%= pkg.version %>.js']
}
},
options: {
banner: '<%= meta.banner %>'
}
},
watch: {
files: '<config:lint.files>',
tasks: 'lint test'
files: '<config:jshint.files>',
tasks: 'jshint test'
},
jshint: {
dist: 'dist/<%= pkg.name %>-<%= pkg.version %>.js',
devel: 'dist/<%= pkg.name %>-devel.js',
options: {
browser: true,
curly: true,
@@ -102,10 +103,29 @@ module.exports = function(grunt) {
qunit: {
noWebRTC: ['test/run-TestNoWebRTC.html']
},
uglify: {}
includereplace: {
dist: {
files: {
'dist': 'dist/<%= pkg.name %>-<%= pkg.version %>.js'
}
},
devel: {
files: {
'dist': 'dist/<%= pkg.name %>-devel.js'
}
}
}
});


// Load Grunt plugins.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-include-replace');

// Task for building JsSIP Grammar.js and Grammar.min.js files.
grunt.registerTask('grammar', function(){
var done = this.async(); // This is an async task.
@@ -143,13 +163,14 @@ module.exports = function(grunt) {
});
});


// Task for building jssip-devel.js (uncompressed), jssip-X.Y.Z.js (uncompressed)
// and jssip-X.Y.Z.min.js (minified).
// Both jssip-devel.js and jssip-X.Y.Z.js are the same file with different name.
grunt.registerTask('build', ['concat:devel', 'lint:devel', 'concat:post_devel', 'concat:dist', 'lint:dist', 'min:dist', 'concat:post', 'concat:post_min']);
grunt.registerTask('build', ['concat:devel', 'includereplace:devel', 'jshint:devel', 'concat:post_devel', 'concat:dist', 'includereplace:dist', 'jshint:dist', 'uglify:dist', 'concat:post', 'concat:post_uglify']);

// Task for building jssip-devel.js (uncompressed).
grunt.registerTask('devel', ['concat:devel', 'lint:devel', 'concat:post_devel']);
grunt.registerTask('devel', ['concat:devel', 'includereplace:devel', 'jshint:devel', 'concat:post_devel']);

// Test tasks.
grunt.registerTask('testNoWebRTC', ['qunit:noWebRTC']);
@@ -162,4 +183,4 @@ module.exports = function(grunt) {
// Default task is an alias for 'build'.
grunt.registerTask('default', ['build']);

};
};
@@ -21,7 +21,7 @@
"library"
],
"devDependencies": {
"grunt": "0.3.17",
"grunt": "~0.4.0",
"pegjs": "0.7.0",
"node-minify": "~0.7.2"
},
@@ -23,6 +23,7 @@ JsSIP.C= {
REQUEST_TIMEOUT: 'Request Timeout',
SIP_FAILURE_CODE: 'SIP Failure Code',
INVALID_TARGET: 'Invalid Target',
INTERNAL_ERROR: 'Internal Error',

// SIP error causes
BUSY: 'Busy',
@@ -37,6 +38,7 @@ JsSIP.C= {

// Session error causes
WEBRTC_NOT_SUPPORTED: 'WebRTC Not Supported',
WEBRTC_ERROR: 'WebRTC Error',
CANCELED: 'Canceled',
NO_ANSWER: 'No Answer',
EXPIRES: 'Expires',
@@ -6,7 +6,7 @@
* @augments JsSIP
* @class Class creating a SIP dialog.
* @param {JsSIP.Session} session
* @param {JsSIP.IncomingRequest|JsSIP.IncomingResponse} msg
* @param {JsSIP.IncomingRequest|JsSIP.IncomingResponse} message
* @param {Enum} type UAC / UAS
* @param {Enum} state JsSIP.Dialog.C.STATUS_EARLY / JsSIP.Dialog.C.STATUS_CONFIRMED
*/
@@ -20,59 +20,56 @@ var Dialog,
};

// RFC 3261 12.1
Dialog = function(session, msg, type, state) {
Dialog = function(session, message, type, state) {
var contact;

if(msg.countHeader('contact') === 0) {
console.warn(LOG_PREFIX + 'no Contact header field, silently discarded');
if(!message.hasHeader('contact')) {
console.error(LOG_PREFIX +'unable to create a Dialog without Contact header field');
return false;
}

if(msg instanceof JsSIP.IncomingResponse) {
state = (msg.status_code < 200) ? C.STATUS_EARLY : C.STATUS_CONFIRMED;
} else if (msg instanceof JsSIP.IncomingRequest) {
if(message instanceof JsSIP.IncomingResponse) {
state = (message.status_code < 200) ? C.STATUS_EARLY : C.STATUS_CONFIRMED;
} else {
// Create confirmed dialog if state is not defined
state = state || C.STATUS_CONFIRMED;
} else {
console.warn(LOG_PREFIX + 'received message is not a SIP request neither a response, silently discarded');
return false;
}

contact = msg.s('contact');
contact = message.parseHeader('contact');

// RFC 3261 12.1.1
if(type === 'UAS') {
this.id = {
call_id: msg.call_id,
local_tag: msg.to_tag,
remote_tag: msg.from_tag,
call_id: message.call_id,
local_tag: message.to_tag,
remote_tag: message.from_tag,
toString: function() {
return this.call_id + this.local_tag + this.remote_tag;
}
};
this.state = state;
this.remote_seqnum = msg.cseq;
this.local_uri = msg.parseHeader('to').uri;
this.remote_uri = msg.parseHeader('from').uri;
this.remote_seqnum = message.cseq;
this.local_uri = message.parseHeader('to').uri;
this.remote_uri = message.parseHeader('from').uri;
this.remote_target = contact.uri;
this.route_set = msg.getHeaderAll('record-route');
this.route_set = message.getHeaderAll('record-route');
}
// RFC 3261 12.1.2
else if(type === 'UAC') {
this.id = {
call_id: msg.call_id,
local_tag: msg.from_tag,
remote_tag: msg.to_tag,
call_id: message.call_id,
local_tag: message.from_tag,
remote_tag: message.to_tag,
toString: function() {
return this.call_id + this.local_tag + this.remote_tag;
}
};
this.state = state;
this.local_seqnum = msg.cseq;
this.local_uri = msg.parseHeader('from').uri;
this.remote_uri = msg.parseHeader('to').uri;
this.local_seqnum = message.cseq;
this.local_uri = message.parseHeader('from').uri;
this.remote_uri = message.parseHeader('to').uri;
this.remote_target = contact.uri;
this.route_set = msg.getHeaderAll('record-route').reverse();
this.route_set = message.getHeaderAll('record-route').reverse();
}

this.session = session;

0 comments on commit 940fb34

Please sign in to comment.
You can’t perform that action at this time.