@babblevoice/babble-drachtio-callmanager 2.3.1 → 2.3.3
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 +52 -20
- package/package.json +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,
|
|
@@ -787,9 +788,11 @@ class call {
|
|
|
787
788
|
/**
|
|
788
789
|
Allows 3rd parties to emit events to listeners specific to this call.
|
|
789
790
|
@param { string } ev - event name
|
|
791
|
+
@param { any } argv1
|
|
790
792
|
*/
|
|
791
|
-
emit( ev ) {
|
|
792
|
-
this._em.emit( ev,
|
|
793
|
+
emit( ev, argv1 ) {
|
|
794
|
+
if( argv1 ) return this._em.emit( ev, argv1 )
|
|
795
|
+
else return this._em.emit( ev, this )
|
|
793
796
|
}
|
|
794
797
|
|
|
795
798
|
/**
|
|
@@ -1314,7 +1317,7 @@ class call {
|
|
|
1314
1317
|
*/
|
|
1315
1318
|
waitfortelevents( match = /[0-9A-D*#]/, timeout = 30000 ) {
|
|
1316
1319
|
|
|
1317
|
-
if( this.destroyed ) throw "Call already destroyed"
|
|
1320
|
+
if( this.destroyed ) throw Error( "Call already destroyed" )
|
|
1318
1321
|
if( this._promises.promise.events ) return this._promises.promise.events
|
|
1319
1322
|
|
|
1320
1323
|
this._promises.promise.events = new Promise( ( resolve ) => {
|
|
@@ -1554,6 +1557,7 @@ class call {
|
|
|
1554
1557
|
|
|
1555
1558
|
const r = this._promises.resolve.channelevent
|
|
1556
1559
|
this._promises.resolve.channelevent = false
|
|
1560
|
+
this._promises.reject.channelevent = false
|
|
1557
1561
|
this._promises.promise.channelevent = false
|
|
1558
1562
|
if( r ) r( e )
|
|
1559
1563
|
}
|
|
@@ -1570,7 +1574,7 @@ class call {
|
|
|
1570
1574
|
} catch ( e ) { console.trace( e ) }
|
|
1571
1575
|
|
|
1572
1576
|
switch( e.action ) {
|
|
1573
|
-
case "close":
|
|
1577
|
+
case "close":
|
|
1574
1578
|
this.#handlechannelevclose( e )
|
|
1575
1579
|
return
|
|
1576
1580
|
case "telephone-event":
|
|
@@ -1595,12 +1599,13 @@ class call {
|
|
|
1595
1599
|
*/
|
|
1596
1600
|
waitforanyevent( constraints, timeout = 500 ) {
|
|
1597
1601
|
|
|
1598
|
-
if( this.destroyed ) throw "Call already destroyed"
|
|
1602
|
+
if( this.destroyed ) throw Error( "Call already destroyed" )
|
|
1599
1603
|
if ( this._promises.promise.channelevent ) return this._promises.promise.channelevent
|
|
1600
1604
|
|
|
1601
1605
|
this._eventconstraints = constraints
|
|
1602
1606
|
|
|
1603
|
-
this._promises.promise.channelevent = new Promise( ( resolve ) => {
|
|
1607
|
+
this._promises.promise.channelevent = new Promise( ( resolve, reject ) => {
|
|
1608
|
+
this._promises.reject.channelevent = reject
|
|
1604
1609
|
this._promises.resolve.channelevent = resolve
|
|
1605
1610
|
} )
|
|
1606
1611
|
|
|
@@ -1608,6 +1613,7 @@ class call {
|
|
|
1608
1613
|
const r = this._promises.resolve.channelevent
|
|
1609
1614
|
this._promises.promise.channelevent = false
|
|
1610
1615
|
this._promises.resolve.channelevent = false
|
|
1616
|
+
this._promises.reject.channelevent = false
|
|
1611
1617
|
if( r ) r( "timeout" )
|
|
1612
1618
|
}, timeout * 1000 )
|
|
1613
1619
|
|
|
@@ -1911,6 +1917,10 @@ class call {
|
|
|
1911
1917
|
other.channels.audio.dtmf( digit )
|
|
1912
1918
|
}
|
|
1913
1919
|
|
|
1920
|
+
try {
|
|
1921
|
+
this._em.emit( "channel", { "call": this, "event": { action: "telephone-event", event: digit, source: "sip-info" } } )
|
|
1922
|
+
} catch ( e ) { console.trace( e ) }
|
|
1923
|
+
|
|
1914
1924
|
return res.send( 200 )
|
|
1915
1925
|
}
|
|
1916
1926
|
|
|
@@ -2246,6 +2256,12 @@ class call {
|
|
|
2246
2256
|
this._promises.resolve.auth = false
|
|
2247
2257
|
if( authreject ) authreject( this )
|
|
2248
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
|
+
|
|
2249
2265
|
const resolves = []
|
|
2250
2266
|
for ( const [ key, value ] of Object.entries( this._promises.resolve ) ) {
|
|
2251
2267
|
if( value ) resolves.push( value )
|
|
@@ -2460,16 +2476,17 @@ class call {
|
|
|
2460
2476
|
|
|
2461
2477
|
/* If max-forwards is not specified then we decrement the parent and pass on */
|
|
2462
2478
|
if( !( "headers" in options ) ) options.headers = {}
|
|
2479
|
+
|
|
2480
|
+
let maxforwards = 70
|
|
2463
2481
|
if( !options.headers[ Object.keys( options.headers ).find( key => "max-forwards" === key.toLowerCase() ) ] ) {
|
|
2464
|
-
if(
|
|
2465
|
-
|
|
2482
|
+
if( this._req.has( "Max-Forwards" ) ) {
|
|
2483
|
+
maxforwards = parseInt( this._req.get( "Max-Forwards" ) ) - 1
|
|
2484
|
+
if( isNaN( maxforwards ) || 0 >= maxforwards ) return false
|
|
2466
2485
|
}
|
|
2467
|
-
|
|
2468
|
-
const maxforwards = parseInt( this._req.get( "Max-Forwards" ) )
|
|
2469
|
-
if( 0 >= maxforwards ) return false
|
|
2470
|
-
options.headers[ "Max-Forwards" ] = maxforwards - 1
|
|
2471
2486
|
}
|
|
2472
2487
|
|
|
2488
|
+
options.headers[ "Max-Forwards" ] = maxforwards
|
|
2489
|
+
|
|
2473
2490
|
if( !options.orphan ) {
|
|
2474
2491
|
options.parent = this
|
|
2475
2492
|
}
|
|
@@ -2491,12 +2508,8 @@ class call {
|
|
|
2491
2508
|
}
|
|
2492
2509
|
return true
|
|
2493
2510
|
}
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
*
|
|
2497
|
-
* @returns { Promise< boolean | object > }
|
|
2498
|
-
*/
|
|
2499
|
-
static async #callcontactfornewuac( options, callbacks ) {
|
|
2511
|
+
|
|
2512
|
+
static async #sanityforcallcontact( options ) {
|
|
2500
2513
|
|
|
2501
2514
|
if( !( await call.#checkmaxcallsforentity( options ) ) ) return false
|
|
2502
2515
|
|
|
@@ -2505,13 +2518,27 @@ class call {
|
|
|
2505
2518
|
if( !options.entity ) return false
|
|
2506
2519
|
|
|
2507
2520
|
const contactinfo = await callmanager.options.registrar.contacts( options.entity )
|
|
2508
|
-
|
|
2509
2521
|
if( 0 == contactinfo.contacts.length )
|
|
2510
2522
|
return false
|
|
2511
2523
|
|
|
2512
2524
|
if( options.first )
|
|
2513
2525
|
contactinfo.contacts = [ contactinfo.contacts[ 0 ] ]
|
|
2514
2526
|
|
|
2527
|
+
return contactinfo
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
/**
|
|
2531
|
+
*
|
|
2532
|
+
* @returns { Promise< boolean | object > }
|
|
2533
|
+
*/
|
|
2534
|
+
static async #callcontactfornewuac( options, callbacks ) {
|
|
2535
|
+
|
|
2536
|
+
const contactinfo = await call.#sanityforcallcontact( options )
|
|
2537
|
+
if( !contactinfo ) {
|
|
2538
|
+
if( callbacks.fail ) callbacks.fail()
|
|
2539
|
+
return false
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2515
2542
|
let numcontacts = 0
|
|
2516
2543
|
const ourcallbacks = {}
|
|
2517
2544
|
let failcount = 0
|
|
@@ -2556,6 +2583,11 @@ class call {
|
|
|
2556
2583
|
}
|
|
2557
2584
|
}
|
|
2558
2585
|
|
|
2586
|
+
if( 0 == numcontacts ) {
|
|
2587
|
+
if( callbacks.fail ) callbacks.fail()
|
|
2588
|
+
return false
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2559
2591
|
const child = await waitonchildrenpromise
|
|
2560
2592
|
return child
|
|
2561
2593
|
}
|