@babblevoice/babble-drachtio-callmanager 2.0.1 → 2.0.2
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 +24 -4
- package/package.json +1 -1
- package/test/interface/serverconnect.js +79 -0
package/lib/call.js
CHANGED
|
@@ -73,6 +73,10 @@ var callmanager = {
|
|
|
73
73
|
/** @class */
|
|
74
74
|
class call {
|
|
75
75
|
|
|
76
|
+
#state = {
|
|
77
|
+
"waitingforevent": false
|
|
78
|
+
}
|
|
79
|
+
|
|
76
80
|
/**
|
|
77
81
|
Construct our call object with all defaults, including a default UUID.
|
|
78
82
|
@constructs call
|
|
@@ -1455,7 +1459,7 @@ class call {
|
|
|
1455
1459
|
/**
|
|
1456
1460
|
Private helper function to add events to our RTP channel.
|
|
1457
1461
|
@param {object} e - the rtp event
|
|
1458
|
-
@
|
|
1462
|
+
@internal
|
|
1459
1463
|
*/
|
|
1460
1464
|
_handlechannelevents( e ) {
|
|
1461
1465
|
|
|
@@ -1485,6 +1489,16 @@ class call {
|
|
|
1485
1489
|
this._tevent( e.event )
|
|
1486
1490
|
}
|
|
1487
1491
|
|
|
1492
|
+
if( !this._promises.resolve.channelevent ) {
|
|
1493
|
+
this.#state.waitingforevent = e
|
|
1494
|
+
return
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
this.#matchandthrow( e )
|
|
1498
|
+
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
#matchandthrow( e ) {
|
|
1488
1502
|
if( this._eventconstraints ) {
|
|
1489
1503
|
let constraintkeys = Object.keys( this._eventconstraints )
|
|
1490
1504
|
for( const k of constraintkeys ) {
|
|
@@ -1492,11 +1506,11 @@ class call {
|
|
|
1492
1506
|
if( "object" === typeof this._eventconstraints[ k ] ) {
|
|
1493
1507
|
/* regex */
|
|
1494
1508
|
if( !e[ k ].match( this._eventconstraints[ k ] ) ) {
|
|
1495
|
-
return
|
|
1509
|
+
return false
|
|
1496
1510
|
}
|
|
1497
1511
|
} else if( this._eventconstraints[ k ] != e[ k ] ) {
|
|
1498
1512
|
/* not a match */
|
|
1499
|
-
return
|
|
1513
|
+
return false
|
|
1500
1514
|
}
|
|
1501
1515
|
}
|
|
1502
1516
|
}
|
|
@@ -1513,7 +1527,7 @@ class call {
|
|
|
1513
1527
|
this._promises.resolve.channelevent = false
|
|
1514
1528
|
this._promises.promise.channelevent = false
|
|
1515
1529
|
if( r ) r( e )
|
|
1516
|
-
|
|
1530
|
+
return true
|
|
1517
1531
|
}
|
|
1518
1532
|
|
|
1519
1533
|
/**
|
|
@@ -1526,6 +1540,7 @@ class call {
|
|
|
1526
1540
|
A telephone event will resolve this promise as we typically need speech to be interupted
|
|
1527
1541
|
by the user. Note, peeking a telephone-event (i.e. DTMF) will not clear it like waitfortelevents will.
|
|
1528
1542
|
@param { regex } constraints - event to filter for from our RTP server - excluding DTMF events - these will always return
|
|
1543
|
+
@returns { Promise< object > }
|
|
1529
1544
|
*/
|
|
1530
1545
|
waitforanyevent( constraints, timeout = 500 ) {
|
|
1531
1546
|
|
|
@@ -1545,6 +1560,11 @@ class call {
|
|
|
1545
1560
|
if( r ) r( "timeout" )
|
|
1546
1561
|
}, timeout * 1000 )
|
|
1547
1562
|
|
|
1563
|
+
if( this.#state.waitingforevent ) {
|
|
1564
|
+
this.#matchandthrow( this.#state.waitingforevent )
|
|
1565
|
+
}
|
|
1566
|
+
this.#state.waitingforevent = false
|
|
1567
|
+
|
|
1548
1568
|
return this._promises.promise.channelevent
|
|
1549
1569
|
}
|
|
1550
1570
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
const prtp = require( "@babblevoice/projectrtp" )
|
|
3
|
+
const node = require( "@babblevoice/projectrtp/lib/node" )
|
|
4
|
+
const expect = require( "chai" ).expect
|
|
5
|
+
const call = require( "../../lib/call" )
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Test file to run tests acting as a remote note. Starts a babble-rtp node in the background
|
|
9
|
+
* before any tests begin then runs tests to open, play, polly etc.
|
|
10
|
+
*/
|
|
11
|
+
describe( "server connect interface", () => {
|
|
12
|
+
|
|
13
|
+
before( async () => {
|
|
14
|
+
const host = "127.0.0.1"
|
|
15
|
+
const port = 9002
|
|
16
|
+
await prtp.projectrtp.node.listen( host, port )
|
|
17
|
+
prtp.projectrtp.server.addnode( { host, port} )
|
|
18
|
+
|
|
19
|
+
} )
|
|
20
|
+
|
|
21
|
+
after( () => {
|
|
22
|
+
prtp.projectrtp.server.clearnodes()
|
|
23
|
+
node.interface.destroy()
|
|
24
|
+
} )
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Primarily testing waitforanyevent and related event handling functions.
|
|
28
|
+
*/
|
|
29
|
+
it( "server connect and open channel", async function () {
|
|
30
|
+
this.timeout( 7000 )
|
|
31
|
+
this.slow( 5000 )
|
|
32
|
+
|
|
33
|
+
const totalotherchannelcount = 100
|
|
34
|
+
let chanclosecount = 0
|
|
35
|
+
let allchannelsclosedresolve
|
|
36
|
+
const allchannelsclosed = new Promise( resolve => allchannelsclosedresolve = resolve )
|
|
37
|
+
const onclose = ( e ) => {
|
|
38
|
+
if( "close" == e.action ) chanclosecount++
|
|
39
|
+
if( totalotherchannelcount == chanclosecount ) allchannelsclosedresolve()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// A very short wav file
|
|
43
|
+
prtp.projectrtp.tone.generate( "350+440*0.5:100", "/tmp/serverconnecttestwavghghgh.wav" )
|
|
44
|
+
prtp.projectrtp.tone.generate( "350+440*0.5:100", "/tmp/otherserverconnecttestwavghhh.wav" )
|
|
45
|
+
|
|
46
|
+
const channels = []
|
|
47
|
+
for( let i = 0; totalotherchannelcount > i; i++ ) {
|
|
48
|
+
channels.push( await prtp.projectrtp.openchannel( onclose ) )
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for( let i = 0; 3 > i; i++ ) {
|
|
52
|
+
const ourcall = new call()
|
|
53
|
+
|
|
54
|
+
const chan = await prtp.projectrtp.openchannel( ourcall._handlechannelevents.bind( ourcall ) )
|
|
55
|
+
|
|
56
|
+
ourcall._em.on( "channel", ( e ) => {
|
|
57
|
+
/* For this test we don't want the call object to run our hangup
|
|
58
|
+
handlers as they are more complex than we are trying to test here */
|
|
59
|
+
if( "close" == e.event.action ) e.event.action = ""
|
|
60
|
+
} )
|
|
61
|
+
|
|
62
|
+
chan.play( { "interupt":true, "files": [ { "wav": "/tmp/serverconnecttestwavghghgh.wav" }, { "wav": "/tmp/otherserverconnecttestwavghhh.wav" } ] } )
|
|
63
|
+
|
|
64
|
+
await ourcall.waitforanyevent( { "action": "play", "event": "start", "reason": "new" } )
|
|
65
|
+
await ourcall.waitforanyevent( { "action": "play", "event": "end", "reason": /^((?!replaced).)*$/ } )
|
|
66
|
+
|
|
67
|
+
chan.close()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for( const chan of channels ) {
|
|
71
|
+
chan.close()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if( 0 != totalotherchannelcount )
|
|
75
|
+
await allchannelsclosed
|
|
76
|
+
expect( chanclosecount ).to.equal( totalotherchannelcount )
|
|
77
|
+
} )
|
|
78
|
+
|
|
79
|
+
} )
|