drachtio-srf 4.5.0 → 4.5.1
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 +103 -89
- package/lib/srf.js +6 -2
- package/package.json +1 -1
package/lib/dialog.js
CHANGED
|
@@ -198,21 +198,24 @@ class Dialog extends Emitter {
|
|
|
198
198
|
|
|
199
199
|
const __x = (callback) => {
|
|
200
200
|
if (this.dialogType === 'INVITE') {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
201
|
+
try {
|
|
202
|
+
this.agent.request({
|
|
203
|
+
method: 'BYE',
|
|
204
|
+
headers: opts.headers || {},
|
|
205
|
+
stackDialogId: this.id,
|
|
206
|
+
auth: opts.auth || this.auth,
|
|
207
|
+
_socket: this.socket
|
|
208
|
+
}, (err, bye) => {
|
|
209
|
+
if (err || !bye) {
|
|
210
|
+
return removeDialog(err, bye, callback);
|
|
211
|
+
}
|
|
212
|
+
bye.on('response', () => {
|
|
213
|
+
removeDialog(err, bye, callback);
|
|
214
|
+
});
|
|
214
215
|
});
|
|
215
|
-
})
|
|
216
|
+
} catch (err) {
|
|
217
|
+
removeDialog(err, null, callback);
|
|
218
|
+
}
|
|
216
219
|
if (this._emitter) {
|
|
217
220
|
Object.assign(this._state, {state: 'terminated'});
|
|
218
221
|
this._emitter.emit('stateChange', this._state);
|
|
@@ -223,14 +226,18 @@ class Dialog extends Emitter {
|
|
|
223
226
|
opts.headers = opts.headers || {} ;
|
|
224
227
|
opts.headers['subscription-state'] = 'terminated';
|
|
225
228
|
opts.headers['event'] = this.subscribeEvent ;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
try {
|
|
230
|
+
this.agent.request({
|
|
231
|
+
method: 'NOTIFY',
|
|
232
|
+
headers: opts.headers || {},
|
|
233
|
+
stackDialogId: this.id,
|
|
234
|
+
_socket: this.socket
|
|
235
|
+
}, (err, notify) => {
|
|
236
|
+
removeDialog(err, notify, callback);
|
|
237
|
+
}) ;
|
|
238
|
+
} catch (err) {
|
|
239
|
+
removeDialog(err, null, callback);
|
|
240
|
+
}
|
|
234
241
|
}
|
|
235
242
|
};
|
|
236
243
|
|
|
@@ -318,43 +325,47 @@ class Dialog extends Emitter {
|
|
|
318
325
|
if (opts.headers && !opts.headers['Contact']) {
|
|
319
326
|
opts.headers['Contact'] = this.local.contact;
|
|
320
327
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if (
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return callback(null, res.body);
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
debug(`opts: ${JSON.stringify(opts)}`);
|
|
347
|
-
debug('SipDialog#modify: go 200 OK to 3pcc INVITE with no sdp; ack is application responsibility');
|
|
348
|
-
return callback(null, res.body, (sdp) => {
|
|
349
|
-
ack({body: sdp});
|
|
328
|
+
try {
|
|
329
|
+
this.agent.request({
|
|
330
|
+
method: 'INVITE',
|
|
331
|
+
stackDialogId: this.id,
|
|
332
|
+
body: this.local.sdp,
|
|
333
|
+
_socket: this.socket,
|
|
334
|
+
headers:
|
|
335
|
+
opts.headers ? opts.headers : {'Contact': this.local.contact}
|
|
336
|
+
}, (err, req) => {
|
|
337
|
+
if (err) {
|
|
338
|
+
this._reinvitesInProgress.count--;
|
|
339
|
+
const admitOne = this._reinvitesInProgress.admitOne.shift();
|
|
340
|
+
if (admitOne) setImmediate(admitOne);
|
|
341
|
+
return callback(err);
|
|
342
|
+
}
|
|
343
|
+
req.on('response', (res, ack) => {
|
|
344
|
+
debug(`Dialog#modifySession: received response to reINVITE with status ${res.status}`) ;
|
|
345
|
+
if (res.status >= 200) {
|
|
346
|
+
if (200 === res.status) {
|
|
347
|
+
this.remote.sdp = res.body ;
|
|
348
|
+
if (this.local.sdp || opts.noAck !== true) {
|
|
349
|
+
ack() ;
|
|
350
350
|
onReInviteComplete(this);
|
|
351
|
-
|
|
351
|
+
return callback(null, res.body);
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
debug(`opts: ${JSON.stringify(opts)}`);
|
|
355
|
+
debug('SipDialog#modify: go 200 OK to 3pcc INVITE with no sdp; ack is application responsibility');
|
|
356
|
+
return callback(null, res.body, (sdp) => {
|
|
357
|
+
ack({body: sdp});
|
|
358
|
+
onReInviteComplete(this);
|
|
359
|
+
});
|
|
360
|
+
}
|
|
352
361
|
}
|
|
362
|
+
callback(new SipError(res.status, res.reason)) ;
|
|
353
363
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
364
|
+
}) ;
|
|
365
|
+
});
|
|
366
|
+
} catch (err) {
|
|
367
|
+
callback(err);
|
|
368
|
+
}
|
|
358
369
|
});
|
|
359
370
|
};
|
|
360
371
|
|
|
@@ -398,45 +409,48 @@ class Dialog extends Emitter {
|
|
|
398
409
|
const __x = (callback) => {
|
|
399
410
|
const method = opts.method.toUpperCase() ;
|
|
400
411
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
req.on('response', (res, ack) => {
|
|
414
|
-
if ('BYE' === method) {
|
|
415
|
-
this.srf.removeDialog(this) ;
|
|
412
|
+
try {
|
|
413
|
+
this.agent.request({
|
|
414
|
+
method: method,
|
|
415
|
+
stackDialogId: this.id,
|
|
416
|
+
headers: opts.headers || {},
|
|
417
|
+
auth: opts.auth || this.auth,
|
|
418
|
+
_socket: this.socket,
|
|
419
|
+
body: opts.body
|
|
420
|
+
}, (err, req) => {
|
|
421
|
+
if (err) {
|
|
422
|
+
return callback(err) ;
|
|
416
423
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
424
|
+
|
|
425
|
+
req.on('response', (res, ack) => {
|
|
426
|
+
if ('BYE' === method) {
|
|
427
|
+
this.srf.removeDialog(this) ;
|
|
428
|
+
}
|
|
429
|
+
if ('INVITE' === method && res.status >= 200) {
|
|
430
|
+
if (res.status > 200 || opts.body || opts.noAck !== true) ack() ;
|
|
431
|
+
else {
|
|
432
|
+
return callback(null, res, ack) ;
|
|
433
|
+
}
|
|
422
434
|
}
|
|
423
|
-
}
|
|
424
435
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
436
|
+
if (this.dialogType === 'SUBSCRIBE' && 'NOTIFY' === method &&
|
|
437
|
+
/terminated/.test(req.get('Subscription-State'))) {
|
|
438
|
+
debug('received response to a NOTIFY we sent terminating final subscription; dialog is ended') ;
|
|
428
439
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
440
|
+
const from = req.getParsedHeader('From');
|
|
441
|
+
if (this.removeSubscription(from.uri, req.get('Event')) === 0) {
|
|
442
|
+
this.connected = false ;
|
|
443
|
+
this.srf.removeDialog(this) ;
|
|
444
|
+
this.emit('destroy', req) ;
|
|
445
|
+
this.removeAllListeners();
|
|
446
|
+
}
|
|
435
447
|
}
|
|
436
|
-
|
|
437
|
-
|
|
448
|
+
callback(null, res) ;
|
|
449
|
+
}) ;
|
|
438
450
|
}) ;
|
|
439
|
-
})
|
|
451
|
+
} catch (err) {
|
|
452
|
+
callback(err);
|
|
453
|
+
}
|
|
440
454
|
} ;
|
|
441
455
|
|
|
442
456
|
if (callback) {
|
package/lib/srf.js
CHANGED
|
@@ -872,7 +872,11 @@ class Srf extends Emitter {
|
|
|
872
872
|
|
|
873
873
|
/* get headers from response on uac (B) leg and ready them for inclusion on our response on uas (A) leg */
|
|
874
874
|
function copyUACHeadersToUAS(uacRes) {
|
|
875
|
-
const headers = {}
|
|
875
|
+
const headers = {};
|
|
876
|
+
if (!uacRes) {
|
|
877
|
+
return headers;
|
|
878
|
+
}
|
|
879
|
+
|
|
876
880
|
if (proxyResponseHeaders[0] === 'all') {
|
|
877
881
|
copyAllHeaders(uacRes, headers);
|
|
878
882
|
possiblyRemoveHeaders(proxyResponseHeaders.slice(1), headers);
|
|
@@ -908,7 +912,7 @@ class Srf extends Emitter {
|
|
|
908
912
|
try {
|
|
909
913
|
const sdpA = await generateSdpA(provisionalRes);
|
|
910
914
|
opts.body = sdpA ;
|
|
911
|
-
return res.send(provisionalRes.status, provisionalRes.reason, opts)
|
|
915
|
+
return res.send(provisionalRes.status, provisionalRes.reason, opts);
|
|
912
916
|
} catch (err) {
|
|
913
917
|
debug(`Srf#createB2BUA: failed in call to produceSdpForALeg: ${err.message}`);
|
|
914
918
|
res.send(500) ;
|