diff --git a/src/Message.js b/src/Message.js index 05d395853..391cdd4b7 100644 --- a/src/Message.js +++ b/src/Message.js @@ -18,8 +18,8 @@ JsSIP.Message = function(ua) { JsSIP.Message.prototype = new JsSIP.EventEmitter(); -JsSIP.Message.prototype.send = function(target, body, contentType, options) { - var request_sender, event, eventHandlers, extraHeaders, +JsSIP.Message.prototype.send = function(target, body, options) { + var request_sender, event, contentType, eventHandlers, extraHeaders, events = [ 'sending', 'succeeded', @@ -34,6 +34,7 @@ JsSIP.Message.prototype.send = function(target, body, contentType, options) { options = options || {}; extraHeaders = options.extraHeaders || []; eventHandlers = options.eventHandlers || {}; + contentType = options.contentType || 'text/plain'; // Set event handlers for (event in eventHandlers) { @@ -54,7 +55,7 @@ JsSIP.Message.prototype.send = function(target, body, contentType, options) { this.closed = false; this.ua.applicants[this] = this; - extraHeaders.push('Content-Type: '+ (contentType ? contentType : 'text/plain')); + extraHeaders.push('Content-Type: '+ contentType); this.request = new JsSIP.OutgoingRequest(JsSIP.C.MESSAGE, target, this.ua, null, extraHeaders); diff --git a/src/Registrator.js b/src/Registrator.js index c7c3f275b..f26ae7db6 100644 --- a/src/Registrator.js +++ b/src/Registrator.js @@ -47,11 +47,15 @@ JsSIP.Registrator = function(ua, transport) { }; JsSIP.Registrator.prototype = { - register: function(extraHeaders) { - var request_sender, cause, + /** + * @param {Object} [options] + */ + register: function(options) { + var request_sender, cause, extraHeaders, self = this; - extraHeaders = extraHeaders || []; + options = options || {}; + extraHeaders = options.extraHeaders || []; extraHeaders.push('Contact: '+ this.contact + ';expires=' + this.expires); extraHeaders.push('Allow: '+ JsSIP.Utils.getAllowedMethods(this.ua)); @@ -164,26 +168,25 @@ JsSIP.Registrator.prototype = { }, /** - * @param {Boolean} [all=false] + * @param {Object} [options] */ - unregister: function(all, extraHeaders) { - /* Parameters: - * - * - all: If true, then perform a "unregister all" action ("Contact: *"); - */ + unregister: function(options) { + var extraHeaders; + if(!this.registered) { console.log(JsSIP.C.LOG_REGISTRATOR +"Already unregistered"); return; } - extraHeaders = extraHeaders || []; + options = options || {}; + extraHeaders = options.extraHeaders || []; this.registered = false; // Clear the registration timer. window.clearTimeout(this.registrationTimer); - if(all) { + if(options.all) { extraHeaders.push('Contact: *'); extraHeaders.push('Expires: 0'); diff --git a/src/Session.js b/src/Session.js index ef94bd02d..96e5679c8 100644 --- a/src/Session.js +++ b/src/Session.js @@ -72,7 +72,7 @@ JsSIP.Session.prototype.init_incoming = function(request) { this.receiveInitialRequest(this.ua, request); }; -JsSIP.Session.prototype.connect = function(target, options) { +JsSIP.Session.prototype.connect = function(target, views, options) { var event, eventHandlers, request, selfView, remoteView, mediaType, extraHeaders, requestParams; // Check UA Status @@ -89,10 +89,16 @@ JsSIP.Session.prototype.connect = function(target, options) { throw new JsSIP.Exceptions.InvalidStateError(); } + // Check views + if (!views || (views && !views.remoteView)) { + console.log(JsSIP.C.LOG_INVITE_SESSION +'Missing "views" or "views.remoteView"'); + throw new JsSIP.Exceptions.InvalidValueError(); + } + // Get call options options = options || {}; - selfView = options.views ? options.views.selfView : null; - remoteView = options.views ? options.views.remoteView : null; + selfView = views.selfView || null; + remoteView = views.remoteView || null; mediaType = options.mediaType || {audio: true, video: true}; extraHeaders = options.extraHeaders || []; eventHandlers = options.eventHandlers || {}; diff --git a/src/UA.js b/src/UA.js index 8326bb3d7..328b85622 100644 --- a/src/UA.js +++ b/src/UA.js @@ -68,10 +68,10 @@ JsSIP.UA.prototype = new JsSIP.EventEmitter(); * * @throws {JsSIP.Exceptions.NotReadyError} If JsSIP.UA is not ready (see JsSIP.UA.status, JsSIP.UA.error parameters). */ -JsSIP.UA.prototype.register = function(extraHeaders) { +JsSIP.UA.prototype.register = function(options) { if(this.status === JsSIP.C.UA_STATUS_READY) { this.configuration.register = true; - this.registrator.register(extraHeaders); + this.registrator.register(options); } else { throw new JsSIP.Exceptions.NotReadyError(); } @@ -83,10 +83,10 @@ JsSIP.UA.prototype.register = function(extraHeaders) { * * @throws {JsSIP.Exceptions.NotReadyError} If JsSIP.UA is not ready (see JsSIP.UA.status, JsSIP.UA.error parameters). */ -JsSIP.UA.prototype.unregister = function(all, extraHeaders) { +JsSIP.UA.prototype.unregister = function(options) { if(this.status === JsSIP.C.UA_STATUS_READY) { this.configuration.register = false; - this.registrator.unregister(all, extraHeaders); + this.registrator.unregister(options); } else { throw new JsSIP.Exceptions.NotReadyError(); } @@ -130,18 +130,11 @@ JsSIP.UA.prototype.isConnected = function() { * @throws {JsSIP.Exceptions.InvalidTargetError} If the calling target is invalid. * */ -JsSIP.UA.prototype.call = function(target, useAudio, useVideo, eventHandlers, videoViews) { - var session, options; - - // Call Options - options = { - views: videoViews, - mediaType: {audio: useAudio, video: useVideo}, - eventHandlers: eventHandlers - }; +JsSIP.UA.prototype.call = function(target, views, options) { + var session; session = new JsSIP.Session(this); - session.connect(target, options); + session.connect(target, views, options); }; /** @@ -155,16 +148,11 @@ JsSIP.UA.prototype.call = function(target, useAudio, useVideo, eventHandlers, vi * @throws {JsSIP.Exceptions.InvalidTargetError} If the calling target is invalid. * */ -JsSIP.UA.prototype.sendMessage = function(target, body, contentType, eventHandlers) { - var message, options; - - // Message Options - options = { - eventHandlers: eventHandlers - }; +JsSIP.UA.prototype.sendMessage = function(target, body, options) { + var message; message = new JsSIP.Message(this); - message.send(target, body, contentType, options); + message.send(target, body, options); }; /**