@babblevoice/babble-drachtio-callmanager 2.3.2 → 2.3.4
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 +49 -11
- package/package.json +1 -1
- package/test/interface/call.js +6 -7
- package/test/interface/early.js +1 -1
package/lib/call.js
CHANGED
|
@@ -277,7 +277,8 @@ class call {
|
|
|
277
277
|
"channelevent": false
|
|
278
278
|
},
|
|
279
279
|
"reject": {
|
|
280
|
-
"auth": false
|
|
280
|
+
"auth": false,
|
|
281
|
+
"channelevent": false
|
|
281
282
|
},
|
|
282
283
|
"promise": {
|
|
283
284
|
"hangup": false,
|
|
@@ -1316,7 +1317,7 @@ class call {
|
|
|
1316
1317
|
*/
|
|
1317
1318
|
waitfortelevents( match = /[0-9A-D*#]/, timeout = 30000 ) {
|
|
1318
1319
|
|
|
1319
|
-
if( this.destroyed ) throw "Call already destroyed"
|
|
1320
|
+
if( this.destroyed ) throw Error( "Call already destroyed" )
|
|
1320
1321
|
if( this._promises.promise.events ) return this._promises.promise.events
|
|
1321
1322
|
|
|
1322
1323
|
this._promises.promise.events = new Promise( ( resolve ) => {
|
|
@@ -1556,6 +1557,7 @@ class call {
|
|
|
1556
1557
|
|
|
1557
1558
|
const r = this._promises.resolve.channelevent
|
|
1558
1559
|
this._promises.resolve.channelevent = false
|
|
1560
|
+
this._promises.reject.channelevent = false
|
|
1559
1561
|
this._promises.promise.channelevent = false
|
|
1560
1562
|
if( r ) r( e )
|
|
1561
1563
|
}
|
|
@@ -1597,12 +1599,13 @@ class call {
|
|
|
1597
1599
|
*/
|
|
1598
1600
|
waitforanyevent( constraints, timeout = 500 ) {
|
|
1599
1601
|
|
|
1600
|
-
if( this.destroyed ) throw "Call already destroyed"
|
|
1602
|
+
if( this.destroyed ) throw Error( "Call already destroyed" )
|
|
1601
1603
|
if ( this._promises.promise.channelevent ) return this._promises.promise.channelevent
|
|
1602
1604
|
|
|
1603
1605
|
this._eventconstraints = constraints
|
|
1604
1606
|
|
|
1605
|
-
this._promises.promise.channelevent = new Promise( ( resolve ) => {
|
|
1607
|
+
this._promises.promise.channelevent = new Promise( ( resolve, reject ) => {
|
|
1608
|
+
this._promises.reject.channelevent = reject
|
|
1606
1609
|
this._promises.resolve.channelevent = resolve
|
|
1607
1610
|
} )
|
|
1608
1611
|
|
|
@@ -1610,6 +1613,7 @@ class call {
|
|
|
1610
1613
|
const r = this._promises.resolve.channelevent
|
|
1611
1614
|
this._promises.promise.channelevent = false
|
|
1612
1615
|
this._promises.resolve.channelevent = false
|
|
1616
|
+
this._promises.reject.channelevent = false
|
|
1613
1617
|
if( r ) r( "timeout" )
|
|
1614
1618
|
}, timeout * 1000 )
|
|
1615
1619
|
|
|
@@ -2252,6 +2256,12 @@ class call {
|
|
|
2252
2256
|
this._promises.resolve.auth = false
|
|
2253
2257
|
if( authreject ) authreject( this )
|
|
2254
2258
|
|
|
2259
|
+
const chanev = this._promises.reject.channelevent
|
|
2260
|
+
this._promises.resolve.channelevent = false
|
|
2261
|
+
this._promises.reject.channelevent = false
|
|
2262
|
+
this._promises.promise.channelevent = false
|
|
2263
|
+
if( chanev ) chanev( Error( "Call hungup" ) )
|
|
2264
|
+
|
|
2255
2265
|
const resolves = []
|
|
2256
2266
|
for ( const [ key, value ] of Object.entries( this._promises.resolve ) ) {
|
|
2257
2267
|
if( value ) resolves.push( value )
|
|
@@ -2384,20 +2394,17 @@ class call {
|
|
|
2384
2394
|
}
|
|
2385
2395
|
|
|
2386
2396
|
/* Check client supports update */
|
|
2387
|
-
if( !this.
|
|
2388
|
-
if(
|
|
2389
|
-
const allow = this._req.get( "Allow" )
|
|
2390
|
-
if( !/\bupdate\b/i.test( allow ) ) return false
|
|
2397
|
+
if( !this._allow ) return false
|
|
2398
|
+
if( !/\bupdate\b/i.test( this._allow ) ) return false
|
|
2391
2399
|
|
|
2392
2400
|
const requestoptions = {}
|
|
2393
|
-
requestoptions.method = "
|
|
2401
|
+
requestoptions.method = "UPDATE"
|
|
2394
2402
|
if( this.sdp.local ) {
|
|
2395
2403
|
requestoptions.body = this.sdp.local.toString()
|
|
2396
2404
|
}
|
|
2397
2405
|
|
|
2398
2406
|
requestoptions.headers = {}
|
|
2399
|
-
|
|
2400
|
-
const remoteidheader = "P-Preferred-Identity"
|
|
2407
|
+
|
|
2401
2408
|
let name = ""
|
|
2402
2409
|
let user = "0000000000"
|
|
2403
2410
|
let realm = "localhost.localdomain"
|
|
@@ -2416,6 +2423,8 @@ class call {
|
|
|
2416
2423
|
}
|
|
2417
2424
|
}
|
|
2418
2425
|
|
|
2426
|
+
/* RFC 3325 - should we also consider the P-Preferred-Identity header? */
|
|
2427
|
+
const remoteidheader = "P-Asserted-Identity"
|
|
2419
2428
|
const remoteid = `"${name}" <sip:${user}@${realm}>`
|
|
2420
2429
|
requestoptions.headers[ remoteidheader ] = remoteid
|
|
2421
2430
|
|
|
@@ -2878,6 +2887,9 @@ class call {
|
|
|
2878
2887
|
},
|
|
2879
2888
|
cbProvisional: async ( res ) => {
|
|
2880
2889
|
newcall._res = res
|
|
2890
|
+
|
|
2891
|
+
newcall.parseallow( res )
|
|
2892
|
+
|
|
2881
2893
|
if( 180 === res.status ) {
|
|
2882
2894
|
newcall._onring()
|
|
2883
2895
|
} else if( 183 === res.status ) {
|
|
@@ -2918,6 +2930,30 @@ class call {
|
|
|
2918
2930
|
this.established = true
|
|
2919
2931
|
}
|
|
2920
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
|
+
|
|
2921
2957
|
/**
|
|
2922
2958
|
Create a new object when we receive an INVITE request.
|
|
2923
2959
|
|
|
@@ -2957,6 +2993,8 @@ class call {
|
|
|
2957
2993
|
*/
|
|
2958
2994
|
c._res = res
|
|
2959
2995
|
|
|
2996
|
+
c.parseallow( req )
|
|
2997
|
+
|
|
2960
2998
|
c._req.on( "cancel", () => c._oncanceled.bind( c ) )
|
|
2961
2999
|
|
|
2962
3000
|
await callstore.set( c )
|
package/package.json
CHANGED
package/test/interface/call.js
CHANGED
|
@@ -251,13 +251,13 @@ describe( "call object", function() {
|
|
|
251
251
|
/* mock */
|
|
252
252
|
let requestoptions = false
|
|
253
253
|
|
|
254
|
-
child.
|
|
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( "
|
|
260
|
-
expect( requestoptions.headers[ "P-
|
|
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.
|
|
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( "
|
|
847
|
+
expect( requestoptions.method ).to.equal( "UPDATE" )
|
|
849
848
|
expect( requestoptions.body ).to.be.a( "string" )
|
|
850
|
-
expect( requestoptions.headers[ "P-
|
|
849
|
+
expect( requestoptions.headers[ "P-Asserted-Identity" ] ).to.equal( "\"Kermit\" <sip:kermy@muppetshow.com>" )
|
|
851
850
|
|
|
852
851
|
} )
|
|
853
852
|
|
package/test/interface/early.js
CHANGED
|
@@ -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
|