Skip to content

Commit 9af96e9

Browse files
committed
Clean up module dependencies.
- LoggerFactory does not depend on SIP - Constants depends only on SIP.name and SIP.version - Exceptions does not depend on SIP - Timers does not depend on SIP - Transport depends on window - SIP.MediaHandler depends on EventEmitter, not SIP - WebRTC depends on Utils, not SIP - Hacks depends on window, not SIP - DigestAuthentication depends on Utils, not SIP
1 parent df33833 commit 9af96e9

File tree

10 files changed

+38
-49
lines changed

10 files changed

+38
-49
lines changed

src/Constants.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* @augments SIP
88
*/
99

10-
module.exports = function (SIP) {
11-
SIP.C= {
12-
USER_AGENT: SIP.name +'/'+ SIP.version,
10+
module.exports = function (name, version) {
11+
return {
12+
USER_AGENT: name +'/'+ version,
1313

1414
// SIP scheme
1515
SIP: 'sip',

src/DigestAuthentication.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @function Digest Authentication
1010
* @param {SIP.UA} ua
1111
*/
12-
module.exports = function (SIP) {
12+
module.exports = function (Utils) {
1313
var DigestAuthentication;
1414

1515
DigestAuthentication = function(ua) {
@@ -78,7 +78,7 @@ DigestAuthentication.prototype.authenticate = function(request, challenge) {
7878

7979
this.method = request.method;
8080
this.uri = request.ruri;
81-
this.cnonce = SIP.Utils.createRandomToken(12);
81+
this.cnonce = Utils.createRandomToken(12);
8282
this.nc += 1;
8383
this.updateNcHex();
8484

@@ -103,25 +103,25 @@ DigestAuthentication.prototype.calculateResponse = function() {
103103
var ha1, ha2;
104104

105105
// HA1 = MD5(A1) = MD5(username:realm:password)
106-
ha1 = SIP.Utils.calculateMD5(this.username + ":" + this.realm + ":" + this.password);
106+
ha1 = Utils.calculateMD5(this.username + ":" + this.realm + ":" + this.password);
107107

108108
if (this.qop === 'auth') {
109109
// HA2 = MD5(A2) = MD5(method:digestURI)
110-
ha2 = SIP.Utils.calculateMD5(this.method + ":" + this.uri);
110+
ha2 = Utils.calculateMD5(this.method + ":" + this.uri);
111111
// response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2)
112-
this.response = SIP.Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + this.ncHex + ":" + this.cnonce + ":auth:" + ha2);
112+
this.response = Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + this.ncHex + ":" + this.cnonce + ":auth:" + ha2);
113113

114114
} else if (this.qop === 'auth-int') {
115115
// HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody))
116-
ha2 = SIP.Utils.calculateMD5(this.method + ":" + this.uri + ":" + SIP.Utils.calculateMD5(this.body ? this.body : ""));
116+
ha2 = Utils.calculateMD5(this.method + ":" + this.uri + ":" + Utils.calculateMD5(this.body ? this.body : ""));
117117
// response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2)
118-
this.response = SIP.Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + this.ncHex + ":" + this.cnonce + ":auth-int:" + ha2);
118+
this.response = Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + this.ncHex + ":" + this.cnonce + ":auth-int:" + ha2);
119119

120120
} else if (this.qop === null) {
121121
// HA2 = MD5(A2) = MD5(method:digestURI)
122-
ha2 = SIP.Utils.calculateMD5(this.method + ":" + this.uri);
122+
ha2 = Utils.calculateMD5(this.method + ":" + this.uri);
123123
// response = MD5(HA1:nonce:HA2)
124-
this.response = SIP.Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + ha2);
124+
this.response = Utils.calculateMD5(ha1 + ":" + this.nonce + ":" + ha2);
125125
}
126126
};
127127

@@ -164,5 +164,5 @@ DigestAuthentication.prototype.updateNcHex = function() {
164164
this.ncHex = '00000000'.substr(0, 8-hex.length) + hex;
165165
};
166166

167-
SIP.DigestAuthentication = DigestAuthentication;
167+
return DigestAuthentication;
168168
};

src/Exceptions.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
* SIP Exceptions.
77
* @augments SIP
88
*/
9-
module.exports = function (SIP) {
10-
var Exceptions;
11-
12-
Exceptions= {
9+
module.exports = {
1310
ConfigurationError: (function(){
1411
var exception = function(parameter, value) {
1512
this.code = 1;
@@ -53,6 +50,3 @@ Exceptions= {
5350
return exception;
5451
}())
5552
};
56-
57-
SIP.Exceptions = Exceptions;
58-
};

src/Hacks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* as to most easily track when particular hacks may not be necessary anymore.
77
*/
88

9-
module.exports = function (SIP) {
9+
module.exports = function (window) {
1010

1111
var Hacks;
1212

@@ -94,5 +94,5 @@ Hacks = {
9494
};
9595

9696

97-
SIP.Hacks = Hacks;
97+
return Hacks;
9898
};

src/LoggerFactory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
module.exports = function (SIP, window, Logger) {
2+
module.exports = function (window, Logger) {
33

44
// Console is not defined in ECMAScript, so just in case...
55
var console = window.console || {
@@ -149,5 +149,5 @@ LoggerFactory.prototype.getLogger = function(category, label) {
149149
}
150150
};
151151

152-
SIP.LoggerFactory = LoggerFactory;
152+
return LoggerFactory;
153153
};

src/MediaHandler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
* @param {SIP.Session} session
88
* @param {Object} [options]
99
*/
10-
module.exports = function (SIP) {
10+
module.exports = function (EventEmitter) {
1111
var MediaHandler = function(session, options) {
1212
// keep jshint happy
1313
session = session;
1414
options = options;
1515
};
1616

17-
MediaHandler.prototype = Object.create(SIP.EventEmitter.prototype, {
17+
MediaHandler.prototype = Object.create(EventEmitter.prototype, {
1818
isReady: {value: function isReady () {}},
1919

2020
close: {value: function close () {}},
@@ -46,5 +46,5 @@ MediaHandler.prototype = Object.create(SIP.EventEmitter.prototype, {
4646
}}
4747
});
4848

49-
SIP.MediaHandler = MediaHandler;
49+
return MediaHandler;
5050
};

src/SIP.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ module.exports = (function(window) {
1818

1919
require('./Utils.js')(SIP);
2020
var Logger = require('./Logger.js');
21-
require('./LoggerFactory.js')(SIP, window, Logger);
21+
SIP.LoggerFactory = require('./LoggerFactory.js')(window, Logger);
2222
require('./EventEmitter.js')(SIP);
23-
require('./Constants.js')(SIP);
24-
require('./Exceptions.js')(SIP);
25-
require('./Timers.js')(SIP);
23+
SIP.C = require('./Constants.js')(SIP.name, SIP.version);
24+
SIP.Exceptions = require('./Exceptions.js');
25+
SIP.Timers = require('./Timers.js');
2626
require('./Transport.js')(SIP, window);
2727
require('./Parser.js')(SIP);
2828
require('./SIPMessage.js')(SIP);
@@ -33,19 +33,19 @@ module.exports = (function(window) {
3333
require('./Dialogs.js')(SIP, DialogRequestSender);
3434
require('./RequestSender.js')(SIP);
3535
require('./RegisterContext.js')(SIP, window);
36-
require('./MediaHandler.js')(SIP);
36+
SIP.MediaHandler = require('./MediaHandler.js')(SIP.EventEmitter);
3737
require('./ClientContext.js')(SIP);
3838
require('./ServerContext.js')(SIP);
3939
var SessionDTMF = require('./Session/DTMF.js')(SIP);
4040
require('./Session.js')(SIP, window, SessionDTMF);
4141
require('./Subscription.js')(SIP, window);
4242
var WebRTCMediaHandler = require('./WebRTC/MediaHandler.js')(SIP);
4343
var WebRTCMediaStreamManager = require('./WebRTC/MediaStreamManager.js')(SIP);
44-
require('./WebRTC.js')(SIP, window, WebRTCMediaHandler, WebRTCMediaStreamManager);
44+
SIP.WebRTC = require('./WebRTC.js')(SIP.Utils, window, WebRTCMediaHandler, WebRTCMediaStreamManager);
4545
require('./UA.js')(SIP, window);
46-
require('./Hacks.js')(SIP, window);
46+
SIP.Hacks = require('./Hacks.js')(window);
4747
require('./SanityCheck.js')(SIP);
48-
require('./DigestAuthentication.js')(SIP);
48+
SIP.DigestAuthentication = require('./DigestAuthentication.js')(SIP.Utils);
4949
SIP.Grammar = require('./Grammar/dist/Grammar');
5050

5151
return SIP;

src/Timers.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
/**
66
* @augments SIP
77
*/
8-
module.exports = function (SIP) {
9-
var Timers,
8+
var
109
T1 = 500,
1110
T2 = 4000,
1211
T4 = 5000;
13-
14-
Timers = {
12+
module.exports = {
1513
T1: T1,
1614
T2: T2,
1715
T4: T4,
@@ -27,6 +25,3 @@ Timers = {
2725
TIMER_N: 64 * T1,
2826
PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1
2927
};
30-
31-
SIP.Timers = Timers;
32-
};

src/Transport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @param {SIP.UA} ua
99
* @param {Object} server ws_server Object
1010
*/
11-
module.exports = function (SIP) {
11+
module.exports = function (SIP, window) {
1212
var Transport,
1313
C = {
1414
// Transport status codes

src/WebRTC.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
* @fileoverview WebRTC
33
*/
44

5-
module.exports = function (SIP, window, MediaHandler, MediaStreamManager) {
5+
module.exports = function (Utils, window, MediaHandler, MediaStreamManager) {
66
var WebRTC;
77

88
WebRTC = {};
99

1010
WebRTC.MediaHandler = MediaHandler;
1111
WebRTC.MediaStreamManager = MediaStreamManager;
1212

13-
WebRTC.MediaStream = SIP.Utils.getPrefixedProperty(window, 'MediaStream');
14-
WebRTC.getUserMedia = SIP.Utils.getPrefixedProperty(window.navigator, 'getUserMedia');
15-
WebRTC.RTCPeerConnection = SIP.Utils.getPrefixedProperty(window, 'RTCPeerConnection');
16-
WebRTC.RTCSessionDescription = SIP.Utils.getPrefixedProperty(window, 'RTCSessionDescription');
13+
WebRTC.MediaStream = Utils.getPrefixedProperty(window, 'MediaStream');
14+
WebRTC.getUserMedia = Utils.getPrefixedProperty(window.navigator, 'getUserMedia');
15+
WebRTC.RTCPeerConnection = Utils.getPrefixedProperty(window, 'RTCPeerConnection');
16+
WebRTC.RTCSessionDescription = Utils.getPrefixedProperty(window, 'RTCSessionDescription');
1717

1818
if (WebRTC.getUserMedia && WebRTC.RTCPeerConnection && WebRTC.RTCSessionDescription) {
1919
WebRTC.getUserMedia = WebRTC.getUserMedia.bind(window.navigator);
@@ -23,5 +23,5 @@ else {
2323
WebRTC.isSupported = false;
2424
}
2525

26-
SIP.WebRTC = WebRTC;
26+
return WebRTC;
2727
};

0 commit comments

Comments
 (0)