@babblevoice/babble-drachtio-callmanager 2.3.3 → 2.3.5

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/call.js CHANGED
@@ -2394,20 +2394,17 @@ class call {
2394
2394
  }
2395
2395
 
2396
2396
  /* Check client supports update */
2397
- if( !this._req ) return false
2398
- if( !this._req.has( "Allow" ) ) return false
2399
- const allow = this._req.get( "Allow" )
2400
- if( !/\bupdate\b/i.test( allow ) ) return false
2397
+ if( !this._allow ) return false
2398
+ if( !/\bupdate\b/i.test( this._allow ) ) return false
2401
2399
 
2402
2400
  const requestoptions = {}
2403
- requestoptions.method = "update"
2401
+ requestoptions.method = "UPDATE"
2404
2402
  if( this.sdp.local ) {
2405
2403
  requestoptions.body = this.sdp.local.toString()
2406
2404
  }
2407
2405
 
2408
2406
  requestoptions.headers = {}
2409
-
2410
- const remoteidheader = "P-Preferred-Identity"
2407
+
2411
2408
  let name = ""
2412
2409
  let user = "0000000000"
2413
2410
  let realm = "localhost.localdomain"
@@ -2426,8 +2423,10 @@ class call {
2426
2423
  }
2427
2424
  }
2428
2425
 
2426
+ /* RFC 3325 - should we also consider the P-Preferred-Identity header? */
2429
2427
  const remoteid = `"${name}" <sip:${user}@${realm}>`
2430
- requestoptions.headers[ remoteidheader ] = remoteid
2428
+ requestoptions.headers[ "P-Asserted-Identity" ] = remoteid
2429
+ requestoptions.headers[ "FROM" ] = remoteid
2431
2430
 
2432
2431
  this._dialog.request( requestoptions )
2433
2432
  return true
@@ -2888,6 +2887,9 @@ class call {
2888
2887
  },
2889
2888
  cbProvisional: async ( res ) => {
2890
2889
  newcall._res = res
2890
+
2891
+ newcall.parseallow( res )
2892
+
2891
2893
  if( 180 === res.status ) {
2892
2894
  newcall._onring()
2893
2895
  } else if( 183 === res.status ) {
@@ -2928,6 +2930,30 @@ class call {
2928
2930
  this.established = true
2929
2931
  }
2930
2932
 
2933
+ /**
2934
+ * Take as input a request or a response.
2935
+ *
2936
+ * @param { object } req
2937
+ */
2938
+ parseallow( req ) {
2939
+ if( !req || !req.get ) return
2940
+
2941
+ let allw = req.get( "Allow" )
2942
+ if( "string" === typeof allw ) {
2943
+ allw = allw.trim()
2944
+ allw = allw.replace( /"/g, "" )
2945
+ this._allow = allw.split( /[\s,]+/ )
2946
+ } else {
2947
+ const contact = req.getParsedHeader( "Contact" )
2948
+ if( !contact ) return
2949
+ if( contact[ 0 ].params && contact[ 0 ].params.methods ) {
2950
+ let methods = contact[ 0 ].params && contact[ 0 ].params.methods
2951
+ methods = methods.replace( /"/g, "" )
2952
+ this._allow = methods.split( /[\s,]+/ )
2953
+ }
2954
+ }
2955
+ }
2956
+
2931
2957
  /**
2932
2958
  Create a new object when we receive an INVITE request.
2933
2959
 
@@ -2967,6 +2993,8 @@ class call {
2967
2993
  */
2968
2994
  c._res = res
2969
2995
 
2996
+ c.parseallow( req )
2997
+
2970
2998
  c._req.on( "cancel", () => c._oncanceled.bind( c ) )
2971
2999
 
2972
3000
  await callstore.set( c )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babblevoice/babble-drachtio-callmanager",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "description": "Call processing to create a PBX",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -251,13 +251,13 @@ describe( "call object", function() {
251
251
  /* mock */
252
252
  let requestoptions = false
253
253
 
254
- child._req.set( "ALLOW", "INVITE, UPDATE, OPTIONS" )
254
+ child.parseallow( { get:() => { return "INVITE, UPDATE, OPTIONS" } } )
255
255
  child._dialog.on( "request", ( options ) => requestoptions = options )
256
256
 
257
257
  child.update()
258
258
 
259
- expect( requestoptions.method ).to.equal( "update" )
260
- expect( requestoptions.headers[ "P-Preferred-Identity" ] ).to.equal( "\"\" <sip:0123456789@someotherrealm.com>" )
259
+ expect( requestoptions.method ).to.equal( "UPDATE" )
260
+ expect( requestoptions.headers[ "P-Asserted-Identity" ] ).to.equal( "\"\" <sip:0123456789@someotherrealm.com>" )
261
261
 
262
262
  await call.hangup()
263
263
 
@@ -829,11 +829,10 @@ describe( "call object", function() {
829
829
  "late": true
830
830
  }
831
831
 
832
- const earlycallbackcalled = false
833
832
  const c = await call.newuac( options )
834
833
 
835
834
  /* mock */
836
- c._req.set( "ALLOW", "INVITE, UPDATE, OPTIONS" )
835
+ c.parseallow( { get:() => { return "INVITE, UPDATE, OPTIONS" } } )
837
836
  let requestoptions
838
837
  c._dialog.on( "request", ( options ) => requestoptions = options )
839
838
 
@@ -845,9 +844,9 @@ describe( "call object", function() {
845
844
 
846
845
  c.hangup()
847
846
 
848
- expect( requestoptions.method ).to.equal( "update" )
847
+ expect( requestoptions.method ).to.equal( "UPDATE" )
849
848
  expect( requestoptions.body ).to.be.a( "string" )
850
- expect( requestoptions.headers[ "P-Preferred-Identity" ] ).to.equal( "\"Kermit\" <sip:kermy@muppetshow.com>" )
849
+ expect( requestoptions.headers[ "P-Asserted-Identity" ] ).to.equal( "\"Kermit\" <sip:kermy@muppetshow.com>" )
851
850
 
852
851
  } )
853
852
 
@@ -105,6 +105,7 @@ describe( "call early", function() {
105
105
  /* Step 3. This is the mocked gateway message back to our newcall. */
106
106
  callbacks.cbProvisional( {
107
107
  "status": 183,
108
+ "get": () => { return "INVITE, UPDATE, OPTIONS" },
108
109
  "msg": {
109
110
  "body": `v=0
110
111
  o=- 1608235282228 0 IN IP4 127.0.0.1
@@ -140,7 +141,6 @@ a=sendrecv`.replace(/(\r\n|\n|\r)/gm, "\r\n")
140
141
  const newcall = await call.newuac( { "contact": "callto" } )
141
142
 
142
143
  await call._onhangup( "wire" )
143
-
144
144
  expect( newcall.state.early ).to.be.true
145
145
  expect( call.state.early ).to.be.true
146
146
  expect( mixing ).to.be.true