diff --git a/.npmignore b/.npmignore index 1c09d6b7e..c320bf080 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,4 @@ node_modules/ +dist/sip* .grunt _SpecRunner.html diff --git a/Gruntfile.js b/Gruntfile.js index 5018ddf7c..2f118da80 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,45 +2,8 @@ module.exports = function(grunt) { - var srcFiles = [ - 'src/SIP.js', - 'src/Utils.js', - 'src/LoggerFactory.js', - 'src/EventEmitter.js', - 'src/Constants.js', - 'src/Exceptions.js', - 'src/Timers.js', - 'src/Transport.js', - 'src/Parser.js', - 'src/SIPMessage.js', - 'src/URI.js', - 'src/NameAddrHeader.js', - 'src/Transactions.js', - 'src/Dialogs.js', - 'src/RequestSender.js', - 'src/RegisterContext.js', - 'src/MediaHandler.js', - 'src/ClientContext.js', - 'src/ServerContext.js', - 'src/Session.js', - 'src/Subscription.js', - 'src/WebRTC.js', - 'src/UA.js', - 'src/Hacks.js', - 'src/SanityCheck.js', - 'src/DigestAuthentication.js', - 'src/Grammar/dist/Grammar.js', - 'src/tail.js' - ]; - var pkg = grunt.file.readJSON('package.json'); - - // Project configuration. - grunt.initConfig({ - pkg: pkg, - name: pkg.name.replace(/\.js$/, ''), - meta: { - banner: '\ + var banner = '\ /*\n\ * SIP version <%= pkg.version %>\n\ * Copyright (c) 2014-<%= grunt.template.today("yyyy") %> Junction Networks, Inc \n\ @@ -72,45 +35,41 @@ module.exports = function(grunt) { * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\ *\n\ * ~~~ end JsSIP license ~~~\n\ - */\n\n\n' + */\n\n\n'; + + // Project configuration. + grunt.initConfig({ + pkg: pkg, + name: pkg.name.replace(/\.js$/, ''), + meta: { + banner: banner }, - concat: { - dist: { - src: srcFiles, - dest: 'dist/<%= name %>.js', - options: { - banner: '<%= meta.banner %>', - separator: '\n\n', - process: true - }, - nonull: true - }, + browserify: { devel: { - src: srcFiles, - dest: 'dist/<%= name %>-<%= pkg.version %>.js', - options: { - banner: '<%= meta.banner %>', - separator: '\n\n', - process: true + src: 'src/SIP.js', + dest: 'dist/<%= name %>-<%= pkg.version %>.js' + }, + options: { + bundleOptions: { + standalone: 'SIP' }, - nonull: true + postBundleCB: function (err, src, next) { + // prepend the banner and fill in placeholders + src = (banner + src).replace(/<%=(.*)%>/g, function (match, expr) { + return eval(expr) + }); + next(err, src); + } } }, - includereplace: { + copy: { dist: { - files: { - 'dist': 'dist/<%= name %>.js' - } - }, - devel: { - files: { - 'dist': 'dist/<%= name %>-<%= pkg.version %>.js' - } + src: 'dist/<%= name %>-<%= pkg.version %>.js', + dest: 'dist/<%= name %>.js' } }, jshint: { - dist: 'dist/<%= name %>.js', - devel: 'dist/<%= name %>-<%= pkg.version %>.js', + src: 'src/**/*.js', options: { browser: true, curly: true, @@ -128,7 +87,7 @@ module.exports = function(grunt) { supernew: true, globals: { module: true, - define: true, + require: true, global: true } } @@ -165,7 +124,6 @@ module.exports = function(grunt) { src: 'src/Grammar/src/Grammar.pegjs', dest: 'src/Grammar/dist/Grammar.js', options: { - exportVar: 'SIP.Grammar', optimize: 'size', allowedStartRules: [ 'Contact', @@ -200,7 +158,7 @@ module.exports = function(grunt) { }, trimtrailingspaces: { main: { - src: srcFiles, + src: "src/**/*.js", options: { filter: 'isFile', encoding: 'utf8', @@ -212,8 +170,8 @@ module.exports = function(grunt) { // Load Grunt plugins. - grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-include-replace'); + grunt.loadNpmTasks('grunt-browserify'); + grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-jasmine'); @@ -230,6 +188,7 @@ module.exports = function(grunt) { var modified_grammar = grammar.replace(/throw peg.*maxFailPos.*/, 'return -1;'); modified_grammar = modified_grammar.replace(/return peg.*result.*/, 'return data;'); modified_grammar = modified_grammar.replace(/parse:( *)parse/, 'parse:$1function (input, startRule) {return parse(input, {startRule: startRule});}'); + modified_grammar = modified_grammar.replace(/\(function\(\)/, 'function(SIP)').replace(/\}\)\(\)/, '}'); // Don't jshint this big chunk of minified code modified_grammar = @@ -246,12 +205,12 @@ module.exports = function(grunt) { // Task for building sip-devel.js (uncompressed), sip-X.Y.Z.js (uncompressed) // and sip-X.Y.Z.min.js (minified). // Both sip-devel.js and sip-X.Y.Z.js are the same file with different name. - grunt.registerTask('build', ['trimtrailingspaces:main', 'concat:devel', 'includereplace:devel', 'jshint:devel', 'concat:dist', 'includereplace:dist', 'jshint:dist', 'uglify:dist', 'uglify:devel']); + grunt.registerTask('build', ['trimtrailingspaces:main', 'devel', 'copy', 'uglify']); // Task for building sip-devel.js (uncompressed). - grunt.registerTask('devel', ['concat:devel', 'includereplace:devel', 'jshint:devel']); + grunt.registerTask('devel', ['jshint', 'browserify']); - grunt.registerTask('quick', ['concat:dist', 'includereplace:dist']); + grunt.registerTask('quick', ['browserify']); // Test tasks. grunt.registerTask('test',['jasmine']); diff --git a/package.json b/package.json index 3c37a6e17..7a0d9f251 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "title": "SIP.js", "description": "A simple, intuitive, and powerful JavaScript signaling library", "version": "0.6.0", - "main": "dist/sip.js", + "main": "src/SIP.js", "homepage": "http://sipjs.com", "author": "Will Mitchell ", "contributors": [ @@ -23,19 +23,19 @@ "javascript" ], "devDependencies": { - "browserify": "~2.36.0", "grunt": "~0.4.0", "grunt-cli": "~0.1.6", - "grunt-contrib-concat": "~0.1.3", "grunt-contrib-jasmine": "~0.6.0", "grunt-contrib-jshint": ">0.5.0", "grunt-contrib-uglify": "~0.2.0", - "grunt-include-replace": "~0.1.0", "grunt-peg": "~1.3.1", "grunt-trimtrailingspaces": "^0.4.0", "node-minify": "~0.7.2", "pegjs": "0.8.0", - "sdp-transform": "~0.4.0" + "sdp-transform": "~0.4.0", + "grunt-contrib-copy": "^0.5.0", + "browserify": "^4.1.8", + "grunt-browserify": "^2.1.0" }, "engines": { "node": ">=0.8" diff --git a/src/ClientContext.js b/src/ClientContext.js index b1a6ee5d1..ef4ca1c23 100644 --- a/src/ClientContext.js +++ b/src/ClientContext.js @@ -1,4 +1,4 @@ -(function (SIP) { +module.exports = function (SIP) { var ClientContext; ClientContext = function (ua, method, target, options) { @@ -111,4 +111,4 @@ ClientContext.prototype.onTransportError = function () { }; SIP.ClientContext = ClientContext; -}(SIP)); +}; diff --git a/src/Constants.js b/src/Constants.js index 42e9397f3..48131d39d 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -7,8 +7,9 @@ * @augments SIP */ -SIP.C= { - USER_AGENT: SIP.name +'/'+ SIP.version, +module.exports = function (name, version) { +return { + USER_AGENT: name +'/'+ version, // SIP scheme SIP: 'sip', @@ -156,3 +157,4 @@ SIP.C= { 606: 'Not Acceptable' } }; +}; diff --git a/src/Dialog/RequestSender.js b/src/Dialog/RequestSender.js index 3381e064b..db1bef60a 100644 --- a/src/Dialog/RequestSender.js +++ b/src/Dialog/RequestSender.js @@ -14,7 +14,7 @@ * @fileoverview in-Dialog Request Sender */ -(function(SIP) { +module.exports = function (SIP) { var RequestSender; RequestSender = function(dialog, applicant, request) { @@ -90,4 +90,4 @@ RequestSender.prototype = { }; return RequestSender; -}(SIP)); +}; diff --git a/src/Dialogs.js b/src/Dialogs.js index 386e66190..7ece493c7 100644 --- a/src/Dialogs.js +++ b/src/Dialogs.js @@ -10,10 +10,7 @@ * @param {Enum} type UAC / UAS * @param {Enum} state SIP.Dialog.C.STATUS_EARLY / SIP.Dialog.C.STATUS_CONFIRMED */ -(function(SIP) { - -// Load dependencies -var RequestSender = @@include('../src/Dialog/RequestSender.js') +module.exports = function (SIP, RequestSender) { var Dialog, C = { @@ -254,4 +251,4 @@ Dialog.prototype = { Dialog.C = C; SIP.Dialog = Dialog; -}(SIP)); +}; diff --git a/src/DigestAuthentication.js b/src/DigestAuthentication.js index ff0202041..3585f0acc 100644 --- a/src/DigestAuthentication.js +++ b/src/DigestAuthentication.js @@ -9,7 +9,7 @@ * @function Digest Authentication * @param {SIP.UA} ua */ -(function(SIP) { +module.exports = function (Utils) { var DigestAuthentication; DigestAuthentication = function(ua) { @@ -78,7 +78,7 @@ DigestAuthentication.prototype.authenticate = function(request, challenge) { this.method = request.method; this.uri = request.ruri; - this.cnonce = SIP.Utils.createRandomToken(12); + this.cnonce = Utils.createRandomToken(12); this.nc += 1; this.updateNcHex(); @@ -103,25 +103,25 @@ DigestAuthentication.prototype.calculateResponse = function() { var ha1, ha2; // HA1 = MD5(A1) = MD5(username:realm:password) - ha1 = SIP.Utils.calculateMD5(this.username + ":" + this.realm + ":" + this.password); + ha1 = Utils.calculateMD5(this.username + ":" + this.realm + ":" + this.password); if (this.qop === 'auth') { // HA2 = MD5(A2) = MD5(method:digestURI) - ha2 = SIP.Utils.calculateMD5(this.method + ":" + this.uri); + ha2 = Utils.calculateMD5(this.method + ":" + this.uri); // response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2) - this.response = SIP.Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + this.ncHex + ":" + this.cnonce + ":auth:" + ha2); + this.response = Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + this.ncHex + ":" + this.cnonce + ":auth:" + ha2); } else if (this.qop === 'auth-int') { // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)) - ha2 = SIP.Utils.calculateMD5(this.method + ":" + this.uri + ":" + SIP.Utils.calculateMD5(this.body ? this.body : "")); + ha2 = Utils.calculateMD5(this.method + ":" + this.uri + ":" + Utils.calculateMD5(this.body ? this.body : "")); // response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2) - this.response = SIP.Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + this.ncHex + ":" + this.cnonce + ":auth-int:" + ha2); + this.response = Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + this.ncHex + ":" + this.cnonce + ":auth-int:" + ha2); } else if (this.qop === null) { // HA2 = MD5(A2) = MD5(method:digestURI) - ha2 = SIP.Utils.calculateMD5(this.method + ":" + this.uri); + ha2 = Utils.calculateMD5(this.method + ":" + this.uri); // response = MD5(HA1:nonce:HA2) - this.response = SIP.Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + ha2); + this.response = Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + ha2); } }; @@ -164,5 +164,5 @@ DigestAuthentication.prototype.updateNcHex = function() { this.ncHex = '00000000'.substr(0, 8-hex.length) + hex; }; -SIP.DigestAuthentication = DigestAuthentication; -}(SIP)); +return DigestAuthentication; +}; diff --git a/src/EventEmitter.js b/src/EventEmitter.js index 64c464fbf..5e9ceb916 100644 --- a/src/EventEmitter.js +++ b/src/EventEmitter.js @@ -6,7 +6,7 @@ * @augments SIP * @class Class creating an event emitter. */ -(function(SIP) { +module.exports = function (SIP) { var EventEmitter, Event, @@ -209,4 +209,4 @@ EventEmitter.C = C; SIP.EventEmitter = EventEmitter; SIP.Event = Event; -}(SIP)); +}; diff --git a/src/Exceptions.js b/src/Exceptions.js index 8d3ca8f79..a7468cbfc 100644 --- a/src/Exceptions.js +++ b/src/Exceptions.js @@ -6,10 +6,7 @@ * SIP Exceptions. * @augments SIP */ -(function(SIP) { -var Exceptions; - -Exceptions= { +module.exports = { ConfigurationError: (function(){ var exception = function(parameter, value) { this.code = 1; @@ -53,6 +50,3 @@ Exceptions= { return exception; }()) }; - -SIP.Exceptions = Exceptions; -}(SIP)); diff --git a/src/Grammar/dist/Grammar.js b/src/Grammar/dist/Grammar.js index fc91f7b59..a309e6647 100644 --- a/src/Grammar/dist/Grammar.js +++ b/src/Grammar/dist/Grammar.js @@ -1,5 +1,5 @@ /* jshint ignore:start */ -SIP.Grammar = (function() { +module.exports = function(SIP) { /* * Generated by PEG.js 0.8.0. * @@ -1273,5 +1273,5 @@ SIP.Grammar = (function() { SyntaxError: SyntaxError, parse: function (input, startRule) {return parse(input, {startRule: startRule});} }; -})(); +}; /* jshint ignore:end */ diff --git a/src/Hacks.js b/src/Hacks.js index 5dc90bd90..eda3f306b 100644 --- a/src/Hacks.js +++ b/src/Hacks.js @@ -6,7 +6,7 @@ * as to most easily track when particular hacks may not be necessary anymore. */ -(function (SIP) { +module.exports = function (window) { var Hacks; @@ -94,5 +94,5 @@ Hacks = { }; -SIP.Hacks = Hacks; -}(SIP)); +return Hacks; +}; diff --git a/src/Logger.js b/src/Logger.js index 382450891..d8f0af4ff 100644 --- a/src/Logger.js +++ b/src/Logger.js @@ -1,5 +1,5 @@ -(function() { +module.exports = (function() { var Logger = function(logger, category, label) { this.logger = logger; @@ -25,4 +25,4 @@ Logger.prototype.error = function(content) { }; return Logger; -}()); +})(); diff --git a/src/LoggerFactory.js b/src/LoggerFactory.js index 51fdf725e..7ded9928e 100644 --- a/src/LoggerFactory.js +++ b/src/LoggerFactory.js @@ -1,5 +1,5 @@ -(function(SIP) { +module.exports = function (window, Logger) { // Console is not defined in ECMAScript, so just in case... var console = window.console || { @@ -9,8 +9,6 @@ var console = window.console || { error: function () {} }; -var Logger = @@include('../src/Logger.js') - var LoggerFactory = function() { var logger, levels = { @@ -151,5 +149,5 @@ LoggerFactory.prototype.getLogger = function(category, label) { } }; -SIP.LoggerFactory = LoggerFactory; -}(SIP)); +return LoggerFactory; +}; diff --git a/src/MediaHandler.js b/src/MediaHandler.js index 1cd7032a6..fedcd3c28 100644 --- a/src/MediaHandler.js +++ b/src/MediaHandler.js @@ -7,14 +7,14 @@ * @param {SIP.Session} session * @param {Object} [options] */ -(function(SIP){ +module.exports = function (EventEmitter) { var MediaHandler = function(session, options) { // keep jshint happy session = session; options = options; }; -MediaHandler.prototype = Object.create(SIP.EventEmitter.prototype, { +MediaHandler.prototype = Object.create(EventEmitter.prototype, { isReady: {value: function isReady () {}}, close: {value: function close () {}}, @@ -46,5 +46,5 @@ MediaHandler.prototype = Object.create(SIP.EventEmitter.prototype, { }} }); -SIP.MediaHandler = MediaHandler; -}(SIP)); +return MediaHandler; +}; diff --git a/src/NameAddrHeader.js b/src/NameAddrHeader.js index b85a429ed..7ed7a6a4f 100644 --- a/src/NameAddrHeader.js +++ b/src/NameAddrHeader.js @@ -11,7 +11,7 @@ * @param {Object} [parameters] * */ -(function(SIP) { +module.exports = function (SIP) { var NameAddrHeader; NameAddrHeader = function(uri, displayName, parameters) { @@ -93,4 +93,4 @@ NameAddrHeader.parse = function(name_addr_header) { }; SIP.NameAddrHeader = NameAddrHeader; -}(SIP)); +}; diff --git a/src/Parser.js b/src/Parser.js index a6d90f5aa..5f0a0f029 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -7,7 +7,7 @@ * @augments SIP * @namespace */ -(function(SIP) { +module.exports = function (SIP) { var Parser; function getHeader(data, headerStart) { @@ -255,4 +255,4 @@ Parser.parseMessage = function(data, ua) { }; SIP.Parser = Parser; -}(SIP)); +}; diff --git a/src/RegisterContext.js b/src/RegisterContext.js index 83713c9ca..486289436 100644 --- a/src/RegisterContext.js +++ b/src/RegisterContext.js @@ -1,4 +1,4 @@ -(function (SIP) { +module.exports = function (SIP) { var RegisterContext; @@ -274,4 +274,4 @@ RegisterContext.prototype = { SIP.RegisterContext = RegisterContext; -}(SIP)); +}; diff --git a/src/RequestSender.js b/src/RequestSender.js index ba47c52a6..5ed2dc0bf 100644 --- a/src/RequestSender.js +++ b/src/RequestSender.js @@ -9,7 +9,7 @@ * @param {Object} applicant * @param {SIP.UA} ua */ -(function(SIP) { +module.exports = function (SIP) { var RequestSender; RequestSender = function(applicant, ua) { @@ -135,4 +135,4 @@ RequestSender.prototype = { }; SIP.RequestSender = RequestSender; -}(SIP)); +}; diff --git a/src/SIP.js b/src/SIP.js index c521aaabc..1e158892e 100644 --- a/src/SIP.js +++ b/src/SIP.js @@ -2,9 +2,7 @@ * @name SIP * @namespace */ -(function(window) { - -var SIP = (function() { +module.exports = (function(window) { "use strict"; var SIP = {}; @@ -18,5 +16,37 @@ var SIP = (function() { } }); + require('./Utils.js')(SIP); + var Logger = require('./Logger.js'); + SIP.LoggerFactory = require('./LoggerFactory.js')(window, Logger); + require('./EventEmitter.js')(SIP); + SIP.C = require('./Constants.js')(SIP.name, SIP.version); + SIP.Exceptions = require('./Exceptions.js'); + SIP.Timers = require('./Timers.js')(window); + require('./Transport.js')(SIP, window); + require('./Parser.js')(SIP); + require('./SIPMessage.js')(SIP); + require('./URI.js')(SIP); + require('./NameAddrHeader.js')(SIP); + require('./Transactions.js')(SIP, window); + var DialogRequestSender = require('./Dialog/RequestSender.js')(SIP, window); + require('./Dialogs.js')(SIP, DialogRequestSender); + require('./RequestSender.js')(SIP); + require('./RegisterContext.js')(SIP, window); + SIP.MediaHandler = require('./MediaHandler.js')(SIP.EventEmitter); + require('./ClientContext.js')(SIP); + require('./ServerContext.js')(SIP); + var SessionDTMF = require('./Session/DTMF.js')(SIP); + require('./Session.js')(SIP, window, SessionDTMF); + require('./Subscription.js')(SIP, window); + var WebRTCMediaHandler = require('./WebRTC/MediaHandler.js')(SIP); + var WebRTCMediaStreamManager = require('./WebRTC/MediaStreamManager.js')(SIP); + SIP.WebRTC = require('./WebRTC.js')(SIP.Utils, window, WebRTCMediaHandler, WebRTCMediaStreamManager); + require('./UA.js')(SIP, window); + SIP.Hacks = require('./Hacks.js')(window); + require('./SanityCheck.js')(SIP); + SIP.DigestAuthentication = require('./DigestAuthentication.js')(SIP.Utils); + SIP.Grammar = require('./Grammar/dist/Grammar')(SIP); + return SIP; -}()); +})((typeof window !== 'undefined') ? window : global); diff --git a/src/SIPMessage.js b/src/SIPMessage.js index eebca4b5f..5758fa362 100644 --- a/src/SIPMessage.js +++ b/src/SIPMessage.js @@ -2,7 +2,7 @@ * @fileoverview SIP Message */ -(function(SIP) { +module.exports = function (SIP) { var OutgoingRequest, IncomingMessage, @@ -549,4 +549,4 @@ IncomingResponse.prototype = new IncomingMessage(); SIP.OutgoingRequest = OutgoingRequest; SIP.IncomingRequest = IncomingRequest; SIP.IncomingResponse = IncomingResponse; -}(SIP)); +}; diff --git a/src/SanityCheck.js b/src/SanityCheck.js index 67670e4bf..d3689944a 100644 --- a/src/SanityCheck.js +++ b/src/SanityCheck.js @@ -11,7 +11,7 @@ * @param {SIP.Transport} transport * @returns {Boolean} */ -(function(SIP) { +module.exports = function (SIP) { var sanityCheck, logger, message, ua, transport, @@ -224,4 +224,4 @@ sanityCheck = function(m, u, t) { }; SIP.sanityCheck = sanityCheck; -}(SIP)); +}; diff --git a/src/ServerContext.js b/src/ServerContext.js index 5c9954b31..2babd54e8 100644 --- a/src/ServerContext.js +++ b/src/ServerContext.js @@ -1,4 +1,4 @@ -(function (SIP) { +module.exports = function (SIP) { var ServerContext; ServerContext = function (ua, request) { @@ -112,4 +112,4 @@ ServerContext.prototype.onTransportError = function () { }; SIP.ServerContext = ServerContext; -}(SIP)); +}; diff --git a/src/Session.js b/src/Session.js index e17e80862..cdeed0b30 100644 --- a/src/Session.js +++ b/src/Session.js @@ -1,7 +1,4 @@ -(function (SIP) { - -// Load dependencies -var DTMF = @@include('../src/Session/DTMF.js') +module.exports = function (SIP, window, DTMF) { var Session, InviteServerContext, InviteClientContext, C = { @@ -2135,4 +2132,4 @@ InviteClientContext.prototype = { SIP.InviteClientContext = InviteClientContext; -}(SIP)); +}; diff --git a/src/Session/DTMF.js b/src/Session/DTMF.js index 1f148e5d4..3290a2403 100644 --- a/src/Session/DTMF.js +++ b/src/Session/DTMF.js @@ -6,7 +6,7 @@ * @class DTMF * @param {SIP.Session} session */ -(function(SIP) { +module.exports = function (SIP) { var DTMF, C = { @@ -180,4 +180,4 @@ DTMF.prototype.init_incoming = function(request) { DTMF.C = C; return DTMF; -}(SIP)); +}; diff --git a/src/Subscription.js b/src/Subscription.js index 70bb95d6d..7dd952daa 100644 --- a/src/Subscription.js +++ b/src/Subscription.js @@ -7,6 +7,7 @@ * @augments SIP * @class Class creating a SIP Subscription. */ +module.exports = function (SIP) { SIP.Subscription = function (ua, target, event, options) { var events; @@ -282,3 +283,4 @@ SIP.Subscription.prototype = { } } }; +}; diff --git a/src/Timers.js b/src/Timers.js index e93476b21..66418e6d4 100644 --- a/src/Timers.js +++ b/src/Timers.js @@ -5,37 +5,36 @@ /** * @augments SIP */ -(function(SIP) { -var Timers, +var T1 = 500, T2 = 4000, T4 = 5000; - -Timers = { - T1: T1, - T2: T2, - T4: T4, - TIMER_B: 64 * T1, - TIMER_D: 0 * T1, - TIMER_F: 64 * T1, - TIMER_H: 64 * T1, - TIMER_I: 0 * T1, - TIMER_J: 0 * T1, - TIMER_K: 0 * T4, - TIMER_L: 64 * T1, - TIMER_M: 64 * T1, - TIMER_N: 64 * T1, - PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1 -}; - -['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval'] -.forEach(function (name) { - // can't just use window[name].bind(window) since it bypasses jasmine's - // clock-mocking - Timers[name] = function () { - return window[name].apply(window, arguments); +module.exports = function (timers) { + var exports = { + T1: T1, + T2: T2, + T4: T4, + TIMER_B: 64 * T1, + TIMER_D: 0 * T1, + TIMER_F: 64 * T1, + TIMER_H: 64 * T1, + TIMER_I: 0 * T1, + TIMER_J: 0 * T1, + TIMER_K: 0 * T4, + TIMER_L: 64 * T1, + TIMER_M: 64 * T1, + TIMER_N: 64 * T1, + PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1 }; -}); -SIP.Timers = Timers; -}(SIP)); + ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval'] + .forEach(function (name) { + // can't just use timers[name].bind(timers) since it bypasses jasmine's + // clock-mocking + exports[name] = function () { + return timers[name].apply(timers, arguments); + }; + }); + + return exports; +}; diff --git a/src/Transactions.js b/src/Transactions.js index 79e491104..1fb850e56 100644 --- a/src/Transactions.js +++ b/src/Transactions.js @@ -6,7 +6,7 @@ * SIP Transactions module. * @augments SIP */ -(function(SIP) { +module.exports = function (SIP) { var C = { // Transaction states @@ -715,4 +715,4 @@ SIP.Transactions = { InviteServerTransaction: InviteServerTransaction }; -}(SIP)); +}; diff --git a/src/Transport.js b/src/Transport.js index d101bf85d..1591f6790 100644 --- a/src/Transport.js +++ b/src/Transport.js @@ -8,7 +8,7 @@ * @param {SIP.UA} ua * @param {Object} server ws_server Object */ -(function(SIP) { +module.exports = function (SIP, window) { var Transport, C = { // Transport status codes @@ -293,4 +293,4 @@ Transport.prototype = { Transport.C = C; SIP.Transport = Transport; -}(SIP)); +}; diff --git a/src/UA.js b/src/UA.js index 35ad8b2bb..bff43a52b 100644 --- a/src/UA.js +++ b/src/UA.js @@ -7,7 +7,7 @@ * * @param {Object} [configuration.media] gets passed to SIP.MediaHandler.getDescription as mediaHint */ -(function(SIP) { +module.exports = function (SIP) { var UA, C = { // UA status codes @@ -1439,4 +1439,4 @@ UA.configuration_check = { UA.C = C; SIP.UA = UA; -}(SIP)); +}; diff --git a/src/URI.js b/src/URI.js index 0d6056dcb..e9d04649d 100644 --- a/src/URI.js +++ b/src/URI.js @@ -14,7 +14,7 @@ * @param {Object} [headers] * */ -(function(SIP) { +module.exports = function (SIP) { var URI; URI = function(scheme, user, host, port, parameters, headers) { @@ -194,4 +194,4 @@ URI.parse = function(uri) { }; SIP.URI = URI; -}(SIP)); +}; diff --git a/src/Utils.js b/src/Utils.js index 8962a472d..19b678999 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -2,7 +2,7 @@ * @fileoverview Utils */ -(function(SIP) { +module.exports = function (SIP) { var Utils; Utils= { @@ -460,4 +460,4 @@ Utils= { }; SIP.Utils = Utils; -}(SIP)); +}; diff --git a/src/WebRTC.js b/src/WebRTC.js index 6ee484e3a..c83fdca42 100644 --- a/src/WebRTC.js +++ b/src/WebRTC.js @@ -2,14 +2,13 @@ * @fileoverview WebRTC */ -(function(SIP) { +module.exports = function (Utils, window, MediaHandler, MediaStreamManager) { var WebRTC; WebRTC = {}; -WebRTC.MediaHandler = @@include('../src/WebRTC/MediaHandler.js') - -WebRTC.MediaStreamManager = @@include('../src/WebRTC/MediaStreamManager.js') +WebRTC.MediaHandler = MediaHandler; +WebRTC.MediaStreamManager = MediaStreamManager; var _isSupported; @@ -18,10 +17,10 @@ WebRTC.isSupported = function () { return _isSupported; } - WebRTC.MediaStream = SIP.Utils.getPrefixedProperty(window, 'MediaStream'); - WebRTC.getUserMedia = SIP.Utils.getPrefixedProperty(window.navigator, 'getUserMedia'); - WebRTC.RTCPeerConnection = SIP.Utils.getPrefixedProperty(window, 'RTCPeerConnection'); - WebRTC.RTCSessionDescription = SIP.Utils.getPrefixedProperty(window, 'RTCSessionDescription'); + WebRTC.MediaStream = Utils.getPrefixedProperty(window, 'MediaStream'); + WebRTC.getUserMedia = Utils.getPrefixedProperty(window.navigator, 'getUserMedia'); + WebRTC.RTCPeerConnection = Utils.getPrefixedProperty(window, 'RTCPeerConnection'); + WebRTC.RTCSessionDescription = Utils.getPrefixedProperty(window, 'RTCSessionDescription'); if (WebRTC.getUserMedia && WebRTC.RTCPeerConnection && WebRTC.RTCSessionDescription) { WebRTC.getUserMedia = WebRTC.getUserMedia.bind(window.navigator); @@ -33,5 +32,5 @@ WebRTC.isSupported = function () { return _isSupported; }; -SIP.WebRTC = WebRTC; -}(SIP)); +return WebRTC; +}; diff --git a/src/WebRTC/MediaHandler.js b/src/WebRTC/MediaHandler.js index 7385742bd..c5836a4f6 100644 --- a/src/WebRTC/MediaHandler.js +++ b/src/WebRTC/MediaHandler.js @@ -10,7 +10,7 @@ * The MediaStreamManager to acquire/release streams from/to. * If not provided, a default MediaStreamManager will be used. */ -(function(SIP){ +module.exports = function (SIP) { var MediaHandler = function(session, options) { var events = [ @@ -107,7 +107,7 @@ var MediaHandler = function(session, options) { cause: SIP.C.causes.RTP_TIMEOUT, status_code: 200, reason_phrase: SIP.C.causes.RTP_TIMEOUT - }); + }); } else if (e.currentTarget.iceGatheringState === 'complete' && this.iceConnectionState !== 'closed') { self.onIceCompleted(this); }*/ @@ -483,4 +483,4 @@ MediaHandler.prototype = Object.create(SIP.MediaHandler.prototype, { // Return since it will be assigned to a variable. return MediaHandler; -}(SIP)); +}; diff --git a/src/WebRTC/MediaStreamManager.js b/src/WebRTC/MediaStreamManager.js index 330fd0ac3..9c00f5c29 100644 --- a/src/WebRTC/MediaStreamManager.js +++ b/src/WebRTC/MediaStreamManager.js @@ -6,7 +6,7 @@ * @class Manages the acquisition and release of MediaStreams. * @param {mediaHint} [defaultMediaHint] The mediaHint to use if none is provided to acquire() */ -(function(SIP){ +module.exports = function (SIP) { // Default MediaStreamManager provides single-use streams created with getUserMedia var MediaStreamManager = function MediaStreamManager (defaultMediaHint) { @@ -139,4 +139,4 @@ MediaStreamManager.prototype = Object.create(SIP.EventEmitter.prototype, { // Return since it will be assigned to a variable. return MediaStreamManager; -}(SIP)); +}; diff --git a/src/tail.js b/src/tail.js deleted file mode 100644 index 1b516cea4..000000000 --- a/src/tail.js +++ /dev/null @@ -1,22 +0,0 @@ -if (typeof module === "object" && module && typeof module.exports === "object") { - // Expose SIP as module.exports in loaders that implement the Node - // module pattern (including browserify). Do not create the global, since - // the user will be storing it themselves locally, and globals are frowned - // upon in the Node module world. - module.exports = SIP; -} else { - // Otherwise expose SIP to the global object as usual. - window.SIP = SIP; - - // Register as a named AMD module, since SIP can be concatenated with other - // files that may use define, but not via a proper concatenation script that - // understands anonymous AMD modules. A named AMD is safest and most robust - // way to register. Lowercase sip is used because AMD module names are - // derived from file names, and SIP is normally delivered in a lowercase - // file name. - if (typeof define === "function" && define.amd) { - define("sip", [], function () { return SIP; }); - } -} - -})((typeof window !== 'undefined') ? window : global); \ No newline at end of file