drachtio-srf 5.0.23 → 5.0.25

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.
@@ -278,12 +278,14 @@ class DrachtioAgent extends Emitter {
278
278
  // Validate socket type
279
279
  if (!typeSocket(params.socket)) {
280
280
  const err = new Error('provided socket is not a net.Socket or tls.TLSSocket');
281
+ err.code = 'EINVALIDSOCKET';
281
282
  return params.callback(err);
282
283
  }
283
284
 
284
285
  // Check if socket is destroyed
285
286
  if (params.socket.destroyed === true) {
286
287
  const err = new Error('provided socket has been destroyed');
288
+ err.code = 'ESOCKETDESTROYED';
287
289
  return params.callback(err);
288
290
  }
289
291
 
@@ -329,7 +331,13 @@ class DrachtioAgent extends Emitter {
329
331
 
330
332
  }
331
333
  else {
332
- const err = new Error(token[1] || 'request failed');
334
+ const reason = token[1] || 'request failed';
335
+ const err = new Error(reason);
336
+ // Attach a stable, machine-readable code so callers can branch on the failure mode
337
+ // without string-matching the server's human-readable reason. The "dialog not found"
338
+ // case is a common, benign race: an in-dialog request (re-INVITE, UPDATE, BYE, etc.)
339
+ // is sent just as the dialog is torn down, so the server no longer has it (see #157).
340
+ err.code = /unable to find dialog/i.test(reason) ? 'ENODIALOG' : 'EDRACHTIO';
333
341
  params.callback(err);
334
342
  }
335
343
  });
@@ -45,9 +45,10 @@ class SipMessage {
45
45
 
46
46
  get callingName() {
47
47
  const header = this.has('p-asserted-identity') ? this.get('p-asserted-identity') : this.get('from');
48
- const user = header.match(/^"(.+)"\s*<sips?:.+@/);
49
- if (user && user.length > 1) {
50
- return user[1];
48
+ const parts = header.split(/,\s*(?=")/);
49
+ for (const part of parts) {
50
+ const user = part.match(/^"([^"]+)"\s*<sips?:.+@/);
51
+ if (user) return user[1];
51
52
  }
52
53
  return '';
53
54
  }
package/lib/srf.js CHANGED
@@ -9,7 +9,7 @@ const SipError = require('./sip_error');
9
9
  const debug = require('debug')('drachtio:srf');
10
10
  const Socket = require('net').Socket;
11
11
  const noop = () => {};
12
- const idgen = require('short-uuid')();
12
+ const uid = require('short-uuid');
13
13
  const sdpTransform = require('sdp-transform');
14
14
 
15
15
  class DialogState {}
@@ -225,7 +225,7 @@ class Srf extends Emitter {
225
225
  aor: `${uri.user || 'unknown'}@${uri.host || 'unknown'}`,
226
226
  callId: req.get('Call-ID'),
227
227
  localTag: from.params.tag,
228
- id: idgen.new()
228
+ id: uid.generate()
229
229
  };
230
230
  opts.dialogStateEmitter.emit('stateChange', req._dialogState);
231
231
  }
@@ -496,7 +496,7 @@ class Srf extends Emitter {
496
496
  aor: `${uri.user || 'unknown'}@${uri.host || 'unknown'}`,
497
497
  callId: req.get('Call-ID'),
498
498
  localTag: from.params.tag,
499
- id: idgen.new()
499
+ id: uid.generate()
500
500
  };
501
501
  }
502
502
  opts.dialogStateEmitter.emit('stateChange', req._dialogState);
@@ -1054,7 +1054,7 @@ class Srf extends Emitter {
1054
1054
  aor: `${uri.user || 'unknown'}@${uri.host || 'unknown'}`,
1055
1055
  callId: req.get('Call-ID'),
1056
1056
  remoteTag: from.params.tag,
1057
- id: idgen.new()
1057
+ id: uid.generate()
1058
1058
  };
1059
1059
  opts.dialogStateEmitter.emit('stateChange', req._dialogState);
1060
1060
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drachtio-srf",
3
- "version": "5.0.23",
3
+ "version": "5.0.25",
4
4
  "description": "drachtio signaling resource framework",
5
5
  "main": "lib/srf.js",
6
6
  "types": "lib/@types/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "node-noop": "^1.0.0",
30
30
  "only": "^0.0.2",
31
31
  "sdp-transform": "^2.15.0",
32
- "short-uuid": "^5.2.0",
32
+ "short-uuid": "^6.0.3",
33
33
  "sip-methods": "^0.3.0",
34
34
  "sip-status": "^0.1.0",
35
35
  "utils-merge": "^1.0.1",
@@ -167,11 +167,27 @@ describe('Parser', function () {
167
167
  msg.get('From').should.eql('"Dave" <sip:daveh@localhost>;tag=1234');
168
168
  msg.callingName.should.eql('Dave');
169
169
  });
170
- it('should parse calling name', function () {
170
+ it('should parse calling name from multi-valued P-Asserted-Identity with tel and sip URIs', function () {
171
171
  var msg = new SipMessage();
172
- msg.set('From', '"Dave" <sip:daveh@localhost>;tag=1234');
173
- msg.get('From').should.eql('"Dave" <sip:daveh@localhost>;tag=1234');
174
- msg.callingName.should.eql('Dave');
172
+ msg.set('P-Asserted-Identity', '"Cha Van" <tel:+17818955550>');
173
+ msg.set('P-Asserted-Identity', '"Cha Van" <sip:+17818955550@ims.lte.wal.verizon.com>');
174
+ msg.callingName.should.eql('Cha Van');
175
+ });
176
+ it('should parse calling name from single sip P-Asserted-Identity', function () {
177
+ var msg = new SipMessage();
178
+ msg.set('P-Asserted-Identity', '"Jane Doe" <sip:+15551234567@example.com>');
179
+ msg.callingName.should.eql('Jane Doe');
180
+ });
181
+ it('should return empty calling name when P-Asserted-Identity has only tel URI', function () {
182
+ var msg = new SipMessage();
183
+ msg.set('P-Asserted-Identity', '"Jane Doe" <tel:+15551234567>');
184
+ msg.callingName.should.eql('');
185
+ });
186
+ it('should parse calling name when sip URI comes first in multi-valued PAI', function () {
187
+ var msg = new SipMessage();
188
+ msg.set('P-Asserted-Identity', '"Bob Smith" <sip:+15559876543@carrier.net>');
189
+ msg.set('P-Asserted-Identity', '"Bob Smith" <tel:+15559876543>');
190
+ msg.callingName.should.eql('Bob Smith');
175
191
  });
176
192
  });
177
193