@@ -10692,13 +10692,22 @@ module.exports = function (stage) {
10692
10692
10693
10693
'use strict';
10694
10694
10695
+ var byteToHex = function byteToHex(byte) {
10696
+ return ('0' + byte.toString(16)).slice(-2);
10697
+ };
10698
+
10699
+ var generateId = function generateId(len) {
10700
+ var arr = new Uint8Array((len || 40) / 2);
10701
+ window.crypto.getRandomValues(arr);
10702
+ return [].map.call(arr, byteToHex).join("");
10703
+ };
10704
+
10695
10705
/*
10696
10706
*
10697
10707
* DIGEST authenticate
10698
10708
*
10699
10709
*
10700
10710
*/
10701
-
10702
10711
var stringify = function stringify(value) {
10703
10712
return '"' + value + '"';
10704
10713
};
@@ -10780,13 +10789,14 @@ module.exports = function (stage) {
10780
10789
_createClass(authenticate, [{
10781
10790
key: 'register',
10782
10791
value: function register(message, type) {
10783
- /*if (transaction.sended){
10784
- console.log("WWW-Authenticate error")
10785
- return ;
10786
- }*/
10787
10792
//console.log("AUTH REGISTER")
10788
10793
//console.log(message);
10789
10794
var head = message.authenticate;
10795
+ if (!head) {
10796
+ head = this.dialog.authenticate;
10797
+ } else {
10798
+ this.dialog.authenticate = head;
10799
+ }
10790
10800
this.realm = head.realm;
10791
10801
this.nonce = head.nonce;
10792
10802
this.cnonce = head.cnonce;
@@ -10850,7 +10860,8 @@ module.exports = function (stage) {
10850
10860
CallId: /^(.*)@.*$/,
10851
10861
algorithm: /= */,
10852
10862
fromTo: /<sip:(.*)@(.*)>/,
10853
- fromToG: /(.*)?<sip:(.*)@(.*)>/
10863
+ fromToG: /(.*)?<sip:(.*)@(.*)>/,
10864
+ contact: /.*<(sips?:.*)>(.*)?$/
10854
10865
};
10855
10866
10856
10867
var parsefromTo = function parsefromTo(type, value) {
@@ -10928,7 +10939,12 @@ module.exports = function (stage) {
10928
10939
} else {
10929
10940
_this[headName] = headValue;
10930
10941
if (_this[func]) {
10931
- _this[headName] = _this[func](headValue);
10942
+ try {
10943
+ _this[headName] = _this[func](headValue);
10944
+ } catch (e) {
10945
+ _this.message.sip.logger("Parse : " + headName, "ERROR");
10946
+ throw e;
10947
+ }
10932
10948
}
10933
10949
}
10934
10950
});
@@ -11017,43 +11033,29 @@ module.exports = function (stage) {
11017
11033
this.message.method = res[1];
11018
11034
return value;
11019
11035
}
11020
-
11021
- /*setContact (value){
11022
- var parseValue = value.replace(regContact,"$1");
11023
- console.log(parseValue)
11024
- var sp = parseValue.split(";");
11025
- var contact = sp.shift();
11026
- var tab = contact.split(":");
11027
- this.message.contact = tab[0];
11028
- this.message.rport = tab[1];
11029
- for (var i = 0 ; i < sp.length ;i++){
11030
- var res3 = sp[i].split("=");
11031
- //console.log(res3[0] +" : "+ res3[1] );
11032
- this["contact"+res3[0]] = res3[1];
11033
- }
11034
- return value;
11035
- }*/
11036
-
11037
11036
}, {
11038
11037
key: 'setContact',
11039
11038
value: function setContact(value) {
11040
- var regContact = /.*<(sips?:.*)>.*/g;
11041
- //console.log(value)
11042
- var parseValue = regContact.exec(value);
11043
- //console.log(parseValue)
11039
+ var parseValue = regHeaders.contact.exec(value);
11044
11040
if (parseValue) {
11045
11041
this.message.contact = parseValue[1];
11042
+ if (parseValue[2]) {
11043
+ var clean = parseValue[2].replace(/^;(.*)/, "$1");
11044
+ var sp = clean.split(";");
11045
+ for (var i = 0; i < sp.length; i++) {
11046
+ var res = sp[i].split("=");
11047
+ if (!res) {
11048
+ continue;
11049
+ }
11050
+ var name = res[0].toLowerCase();
11051
+ if (name === "expires") {
11052
+ this["contact-" + name] = res[1];
11053
+ }
11054
+ }
11055
+ }
11056
+ } else {
11057
+ throw new Error("Contact parse error : " + value);
11046
11058
}
11047
- /*if ( parseValue[2] ){
11048
- console.log(parseValue[2])
11049
- var clean = parseValue[2].replace("^;(.*)","$1")
11050
- var sp = clean.split(";");
11051
- for (var i = 0 ; i < sp.length ;i++){
11052
- var res3 = sp[i].split("=");
11053
- console.log(res3[0] +" : "+ res3[1] );
11054
- //this["contact"+res3[0]] = res3[1];
11055
- }
11056
- }*/
11057
11059
return value;
11058
11060
}
11059
11061
}, {
@@ -11238,9 +11240,9 @@ module.exports = function (stage) {
11238
11240
var rport = this.transaction.dialog.sip.rport;
11239
11241
var ip = this.transaction.dialog.sip.publicAddress;
11240
11242
11243
+ this.header.via = "Via: " + this.transaction.dialog.sip.via + ";" + "branch=" + this.transaction.branch;
11241
11244
//if ( rport ){
11242
11245
//this.header.via = "Via: "+this.transaction.dialog.sip.version+"/"+this.transaction.dialog.sip.settings.transport+" " +ip+":"+rport+";"+"branch="+this.transaction.branch;
11243
- this.header.via = "Via: " + this.transaction.dialog.sip.via + ";" + "branch=" + this.transaction.branch;
11244
11246
//}else{
11245
11247
//this.header.via = "Via: "+this.transaction.dialog.sip.version+"/"+this.transaction.dialog.sip.settings.transport+" " +ip+":"+this["request-port"]+";"+"branch="+this.transaction.branch;
11246
11248
//}
@@ -11711,7 +11713,7 @@ module.exports = function (stage) {
11711
11713
}, {
11712
11714
key: 'generateCallId',
11713
11715
value: function generateCallId() {
11714
- return parseInt(Math.random() * 1000000000, 10) ;
11716
+ return generateId() + "@nodefony" ;
11715
11717
}
11716
11718
}, {
11717
11719
key: 'generateTag',
@@ -11953,10 +11955,15 @@ module.exports = function (stage) {
11953
11955
}, {
11954
11956
key: 'parseBody',
11955
11957
value: function parseBody() {
11956
- if (this.split[1]) {
11957
- this.body = new bodySip(this, this.split[1]);
11958
- } else {
11959
- this.body = new bodySip(this, "");
11958
+ try {
11959
+ if (this.split[1]) {
11960
+ this.body = new bodySip(this, this.split[1]);
11961
+ } else {
11962
+ this.body = new bodySip(this, "");
11963
+ }
11964
+ } catch (e) {
11965
+ this.sip.logger("SIP parseBody Message :" + this.split[1], "ERROR");
11966
+ throw e;
11960
11967
}
11961
11968
}
11962
11969
}, {
@@ -11966,6 +11973,7 @@ module.exports = function (stage) {
11966
11973
try {
11967
11974
this.header = new headerSip(this, this.split[0]);
11968
11975
} catch (e) {
11976
+ this.sip.logger("SIP parseHeader Message :" + this.split[0], "ERROR");
11969
11977
throw e;
11970
11978
}
11971
11979
} else {
@@ -12095,7 +12103,6 @@ module.exports = function (stage) {
12095
12103
if (this.rport) {
12096
12104
this["request-uri"] = "sip:" + this.userName + "@" + this.publicAddress + ":" + this.rport + ";transport=" + this.transportType;
12097
12105
}
12098
- var transaction = null;
12099
12106
switch (message.code) {
12100
12107
case 401:
12101
12108
case 407:
@@ -12117,24 +12124,22 @@ module.exports = function (stage) {
12117
12124
}
12118
12125
this.registered = message.code;
12119
12126
}
12120
-
12121
- delete this.authenticate;
12122
- this.authenticate = null;
12123
- this.authenticate = new authenticate(message.dialog, this.userName, this.settings.password);
12124
- transaction = this.authenticate.register(message, message.code === 407 ? "proxy" : null);
12125
-
12127
+ delete this.authenticateRegister;
12128
+ this.authenticateRegister = null;
12129
+ this.authenticateRegister = new authenticate(message.dialog, this.userName, this.settings.password);
12130
+ this.authenticateRegister.register(message, message.code === 407 ? "proxy" : null);
12126
12131
break;
12127
12132
case 403:
12128
12133
this.registered = message.code;
12129
12134
//console.log("Forbidden (bad auth)")
12130
- delete this.authenticate ;
12131
- this.authenticate = null;
12135
+ delete this.authenticateRegister ;
12136
+ this.authenticateRegister = null;
12132
12137
this.notificationsCenter.fire("onError", this, message);
12133
12138
break;
12134
12139
case 404:
12135
12140
this.registered = message.code;
12136
- delete this.authenticate ;
12137
- this.authenticate = null;
12141
+ delete this.authenticateRegister ;
12142
+ this.authenticateRegister = null;
12138
12143
this.notificationsCenter.fire("onError", this, message);
12139
12144
break;
12140
12145
case 200:
@@ -12150,14 +12155,19 @@ module.exports = function (stage) {
12150
12155
this.notificationsCenter.fire("onRegister", this, message);
12151
12156
}
12152
12157
this.registered = message.code;
12158
+
12159
+ var expires = message.header["contact-expires"] || this.settings.expires;
12160
+ expires = parseInt(expires, 10) * 900; // 10% (ms)
12153
12161
this.registerInterval = setInterval(function () {
12154
- _this2.register(_this2.userName, _this2.settings.password);
12155
- }, this.settings.expires * 900);
12162
+ _this2.authenticateRegister.register(message);
12163
+ _this2.notificationsCenter.fire("onRenew", _this2, _this2.authenticateRegister, message);
12164
+ //this.register(this.userName, this.settings.password);
12165
+ }, expires);
12156
12166
break;
12157
12167
default:
12158
12168
this.registered = message.code;
12159
- delete this.authenticate ;
12160
- this.authenticate = null;
12169
+ delete this.authenticateRegister ;
12170
+ this.authenticateRegister = null;
12161
12171
//console.log(message);
12162
12172
this.notificationsCenter.fire("on" + message.code, this, message);
12163
12173
break;
@@ -12194,7 +12204,7 @@ module.exports = function (stage) {
12194
12204
delete this.authenticate;
12195
12205
this.authenticate = null;
12196
12206
this.authenticate = new authenticate(message.dialog, this.userName, this.settings.password);
12197
- transaction = this.authenticate.register(message, message.code === 407 ? "proxy" : null);
12207
+ var transaction = this.authenticate.register(message, message.code === 407 ? "proxy" : null);
12198
12208
this.fire("onInitCall", message.dialog.toName, message.dialog, transaction);
12199
12209
break;
12200
12210
case 180:
@@ -12218,8 +12228,6 @@ module.exports = function (stage) {
12218
12228
this.notificationsCenter.fire("onError", this, message);
12219
12229
break;
12220
12230
case 487:
12221
- // ACK !!
12222
- break;
12223
12231
case 404:
12224
12232
case 477:
12225
12233
case 480:
@@ -12344,6 +12352,7 @@ module.exports = function (stage) {
12344
12352
_this3.serverPort = _this3.settings.portServer;
12345
12353
12346
12354
_this3.authenticate = false;
12355
+ _this3.authenticateRegister = null;
12347
12356
12348
12357
// REGISTER
12349
12358
_this3.registerInterval = null;
@@ -17940,7 +17949,11 @@ module.exports = function (stage) {
17940
17949
key: 'close',
17941
17950
value: function close() {
17942
17951
this.logger("WEBRTC CLOSE TRANSACTION : " + this.callId, "DEBUG");
17943
- this.RTCPeerConnection.close();
17952
+ if (this.RTCPeerConnection) {
17953
+ this.RTCPeerConnection.close();
17954
+ } else {
17955
+ this.logger("WEBRTC TRANSACTION ALREADY CLOSED : " + this.callId, "WARNING");
17956
+ }
17944
17957
this.webrtc.unListen("onKeyPress", this.sendDtmf);
17945
17958
delete this.RTCPeerConnection;
17946
17959
return this;
@@ -18191,6 +18204,10 @@ module.exports = function (stage) {
18191
18204
18192
18205
this.protocol.listen(this, "onTimeout", function (sip, message) {
18193
18206
this.notificationsCenter.fire("onTimeout", message.method, 408, message);
18207
+ var transac = this.transactions[message.callId];
18208
+ if (transac) {
18209
+ this.closeTransaction(transac, transac.to.name);
18210
+ }
18194
18211
});
18195
18212
18196
18213
this.protocol.listen(this, "onDecline", function (message) {
0 commit comments