Skip to content

Commit

Permalink
Change API methods to make use of generic 'options' argument
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillan committed Feb 3, 2013
1 parent 72424bd commit 777a48f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
7 changes: 4 additions & 3 deletions src/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) {
Expand All @@ -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);

Expand Down
25 changes: 14 additions & 11 deletions src/Registrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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');

Expand Down
12 changes: 9 additions & 3 deletions src/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 || {};
Expand Down
32 changes: 10 additions & 22 deletions src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
};

/**
Expand All @@ -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);
};

/**
Expand Down

0 comments on commit 777a48f

Please sign in to comment.