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.
Files changed (3) hide show
  1. package/lib/dialog.js +103 -89
  2. package/lib/srf.js +6 -2
  3. 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
- this.agent.request({
202
- method: 'BYE',
203
- headers: opts.headers || {},
204
- stackDialogId: this.id,
205
- auth: opts.auth || this.auth,
206
- _socket: this.socket
207
- }, (err, bye) => {
208
- if (err || !bye) {
209
- return removeDialog(err, bye, callback);
210
- }
211
-
212
- bye.on('response', () => {
213
- removeDialog(err, bye, callback);
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
- this.agent.request({
227
- method: 'NOTIFY',
228
- headers: opts.headers || {},
229
- stackDialogId: this.id,
230
- _socket: this.socket
231
- }, (err, notify) => {
232
- removeDialog(err, notify, callback);
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
- this.agent.request({
322
- method: 'INVITE',
323
- stackDialogId: this.id,
324
- body: this.local.sdp,
325
- _socket: this.socket,
326
- headers:
327
- opts.headers ? opts.headers : {'Contact': this.local.contact}
328
- }, (err, req) => {
329
- if (err) {
330
- this._reinvitesInProgress.count--;
331
- const admitOne = this._reinvitesInProgress.admitOne.shift();
332
- if (admitOne) setImmediate(admitOne);
333
- return callback(err);
334
- }
335
- req.on('response', (res, ack) => {
336
- debug(`Dialog#modifySession: received response to reINVITE with status ${res.status}`) ;
337
- if (res.status >= 200) {
338
- if (200 === res.status) {
339
- this.remote.sdp = res.body ;
340
- if (this.local.sdp || opts.noAck !== true) {
341
- ack() ;
342
- onReInviteComplete(this);
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
- callback(new SipError(res.status, res.reason)) ;
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
- this.agent.request({
402
- method: method,
403
- stackDialogId: this.id,
404
- headers: opts.headers || {},
405
- auth: opts.auth || this.auth,
406
- _socket: this.socket,
407
- body: opts.body
408
- }, (err, req) => {
409
- if (err) {
410
- return callback(err) ;
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
- if ('INVITE' === method && res.status >= 200) {
418
- if (res.status > 200 || opts.body || opts.noAck !== true) ack() ;
419
- else {
420
- debug('SipDialog#request: received 200 OK to 3pcc INVITE sent with no sdp; deferring ack to application');
421
- return callback(null, res, ack) ;
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
- if (this.dialogType === 'SUBSCRIBE' && 'NOTIFY' === method &&
426
- /terminated/.test(req.get('Subscription-State'))) {
427
- debug('received response to a NOTIFY we sent terminating final subscription; dialog is ended') ;
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
- const from = req.getParsedHeader('From');
430
- if (this.removeSubscription(from.uri, req.get('Event')) === 0) {
431
- this.connected = false ;
432
- this.srf.removeDialog(this) ;
433
- this.emit('destroy', req) ;
434
- this.removeAllListeners();
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
- callback(null, res) ;
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) ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drachtio-srf",
3
- "version": "4.5.0",
3
+ "version": "4.5.1",
4
4
  "description": "drachtio signaling resource framework",
5
5
  "main": "lib/srf.js",
6
6
  "scripts": {