drachtio-srf 5.0.24 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drachtio-srf",
3
- "version": "5.0.24",
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",
@@ -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