Skip to content
Permalink
Browse files

Change API methods to make use of generic 'options' argument

  • Loading branch information
jmillan committed Feb 3, 2013
1 parent 72424bd commit 777a48f30e3b1b4fdd4b1b6e9301755d840a31cf
Showing with 37 additions and 39 deletions.
  1. +4 −3 src/Message.js
  2. +14 −11 src/Registrator.js
  3. +9 −3 src/Session.js
  4. +10 −22 src/UA.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);

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

@@ -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 || {};
@@ -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);
};

/**

0 comments on commit 777a48f

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