drachtio-srf 4.4.62 → 4.4.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dialog.js +3 -3
- package/lib/srf.js +18 -11
- package/package.json +1 -1
- package/test/parser.js +8 -0
- package/test/unit-tests/parser.js +6 -0
package/lib/dialog.js
CHANGED
|
@@ -205,8 +205,8 @@ class Dialog extends Emitter {
|
|
|
205
205
|
auth: opts.auth || this.auth,
|
|
206
206
|
_socket: this.socket
|
|
207
207
|
}, (err, bye) => {
|
|
208
|
-
if (err) {
|
|
209
|
-
removeDialog(err, bye, callback);
|
|
208
|
+
if (err || !bye) {
|
|
209
|
+
return removeDialog(err, bye, callback);
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
bye.on('response', () => {
|
|
@@ -323,7 +323,7 @@ class Dialog extends Emitter {
|
|
|
323
323
|
stackDialogId: this.id,
|
|
324
324
|
body: this.local.sdp,
|
|
325
325
|
_socket: this.socket,
|
|
326
|
-
headers:
|
|
326
|
+
headers:
|
|
327
327
|
opts.headers ? opts.headers : {'Contact': this.local.contact}
|
|
328
328
|
}, (err, req) => {
|
|
329
329
|
if (err) {
|
package/lib/srf.js
CHANGED
|
@@ -27,6 +27,8 @@ DialogState.Cancelled = 'cancelled';
|
|
|
27
27
|
DialogDirection.Initiator = 'initiator';
|
|
28
28
|
DialogDirection.Recipient = 'recipient';
|
|
29
29
|
|
|
30
|
+
const sleepFor = async(ms) => await new Promise((resolve) => setTimeout(resolve, ms));
|
|
31
|
+
|
|
30
32
|
const noncopyableHdrs = ['via', 'from', 'to', 'call-id', 'cseq', 'contact', 'content-length', 'content-type'];
|
|
31
33
|
function copyAllHeaders(msg, obj) {
|
|
32
34
|
if (msg) Object.keys(msg.headers).forEach((h) => {
|
|
@@ -833,37 +835,42 @@ class Srf extends Emitter {
|
|
|
833
835
|
let remoteSdpB, translatedRemoteSdpB ;
|
|
834
836
|
|
|
835
837
|
/* returns a Promise that resolves with the sdp to use responding to the A leg */
|
|
836
|
-
|
|
838
|
+
const generateSdpA = async(res) => {
|
|
837
839
|
debug('createB2BUA: generateSdpA');
|
|
838
840
|
|
|
839
841
|
const sdpB = res.body ;
|
|
840
842
|
if (res.getParsedHeader('CSeq').method === 'SUBSCRIBE' || !sdpB) {
|
|
841
|
-
return
|
|
843
|
+
return sdpB ;
|
|
842
844
|
}
|
|
843
845
|
|
|
844
846
|
if (remoteSdpB && remoteSdpB === sdpB) {
|
|
845
847
|
// called again with same remote SDP, return previous result
|
|
846
|
-
|
|
848
|
+
if (translatedRemoteSdpB) return translatedRemoteSdpB;
|
|
849
|
+
|
|
850
|
+
/* race condition: we are still producing the translatedSdp from 183 */
|
|
851
|
+
await sleepFor(100);
|
|
852
|
+
if (translatedRemoteSdpB) return translatedRemoteSdpB;
|
|
853
|
+
await sleepFor(500);
|
|
854
|
+
if (translatedRemoteSdpB) return translatedRemoteSdpB;
|
|
855
|
+
await sleepFor(1000);
|
|
856
|
+
return translatedRemoteSdpB;
|
|
847
857
|
}
|
|
848
858
|
|
|
849
859
|
remoteSdpB = sdpB ;
|
|
850
860
|
if (!opts.localSdpA) {
|
|
851
861
|
// passthru B leg SDP
|
|
852
|
-
return
|
|
862
|
+
return translatedRemoteSdpB = sdpB;
|
|
853
863
|
}
|
|
854
864
|
else if ('function' === typeof opts.localSdpA) {
|
|
855
865
|
// call function that returns either the sdp, or a Promise that resolves to the sdp
|
|
856
|
-
const
|
|
857
|
-
|
|
858
|
-
return p
|
|
859
|
-
.then((sdpA) => translatedRemoteSdpB = sdpA)
|
|
860
|
-
.catch((err) => Promise.reject(err));
|
|
866
|
+
const sdpA = await opts.localSdpA(sdpB, res);
|
|
867
|
+
return translatedRemoteSdpB = sdpA;
|
|
861
868
|
}
|
|
862
869
|
else {
|
|
863
870
|
// insert provided SDP
|
|
864
|
-
return
|
|
871
|
+
return translatedRemoteSdpB = opts.localSdpA ;
|
|
865
872
|
}
|
|
866
|
-
}
|
|
873
|
+
};
|
|
867
874
|
|
|
868
875
|
/* uac request sent, set handler to propagate CANCEL from A leg if we get it */
|
|
869
876
|
function handleUACSent(err, uacReq) {
|
package/package.json
CHANGED
package/test/parser.js
ADDED
|
@@ -2,10 +2,16 @@ require('assert');
|
|
|
2
2
|
require('mocha');
|
|
3
3
|
require('should');
|
|
4
4
|
|
|
5
|
+
const assert = require('assert');
|
|
5
6
|
const examples = require('sip-message-examples');
|
|
6
7
|
const SipMessage = require('../../lib/sip-parser/message');
|
|
7
8
|
const parser = require('../../lib/sip-parser/parser');
|
|
8
9
|
const parseUri = parser.parseUri;
|
|
10
|
+
const Srf = require('../..');
|
|
11
|
+
assert.ok(typeof parseUri === 'function');
|
|
12
|
+
assert.ok(typeof Srf.parseUri === 'function');
|
|
13
|
+
console.log(`typeof parseUri is ${typeof parseUri}`);
|
|
14
|
+
console.log(`typeof Srf.parseUri is ${typeof Srf.parseUri}`);
|
|
9
15
|
|
|
10
16
|
describe('Parser', function () {
|
|
11
17
|
it('should provide headers as string values', function () {
|