@babblevoice/projectrtp 2.5.29 → 2.5.31
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/node.js
CHANGED
|
@@ -15,7 +15,12 @@ const channelmap = {
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"unmix": ( chan ) => chan.unmix(),
|
|
18
|
-
"dtmf": ( chan, msg ) =>
|
|
18
|
+
"dtmf": ( chan, msg ) => {
|
|
19
|
+
if( !msg.digits ) return
|
|
20
|
+
if( "string" !== typeof msg.digits ) return
|
|
21
|
+
if( 10 < msg.digits.length ) return
|
|
22
|
+
chan.dtmf( msg.digits )
|
|
23
|
+
},
|
|
19
24
|
"echo": ( chan ) => chan.echo(),
|
|
20
25
|
"play": ( chan, msg ) => chan.play( msg.soup ),
|
|
21
26
|
"record": ( chan, msg ) => chan.record( msg.options ),
|
package/lib/server.js
CHANGED
package/package.json
CHANGED
|
@@ -312,8 +312,8 @@ describe( "record", function() {
|
|
|
312
312
|
|
|
313
313
|
expect( channel.record( {
|
|
314
314
|
"file": "/tmp/ourpowerrecording.wav",
|
|
315
|
-
"startabovepower":
|
|
316
|
-
"finishbelowpower":
|
|
315
|
+
"startabovepower": 40,
|
|
316
|
+
"finishbelowpower": 80,
|
|
317
317
|
"minduration": 2000,
|
|
318
318
|
"maxduration": 15000,
|
|
319
319
|
"poweraveragepackets": 20
|
|
@@ -382,8 +382,8 @@ describe( "record", function() {
|
|
|
382
382
|
|
|
383
383
|
expect( channel.record( {
|
|
384
384
|
"file": "/tmp/ourtimeoutpowerrecording.wav",
|
|
385
|
-
"startabovepower":
|
|
386
|
-
"finishbelowpower":
|
|
385
|
+
"startabovepower": 40,
|
|
386
|
+
"finishbelowpower": 80,
|
|
387
387
|
"minduration": 200,
|
|
388
388
|
"maxduration": 500,
|
|
389
389
|
"poweraveragepackets": 50
|
|
@@ -449,8 +449,8 @@ describe( "record", function() {
|
|
|
449
449
|
|
|
450
450
|
expect( channel.record( {
|
|
451
451
|
"file": "/tmp/dualrecordingpower.wav",
|
|
452
|
-
"startabovepower":
|
|
453
|
-
"finishbelowpower":
|
|
452
|
+
"startabovepower": 40,
|
|
453
|
+
"finishbelowpower": 200,
|
|
454
454
|
"minduration": 200,
|
|
455
455
|
"maxduration": 3500,
|
|
456
456
|
"poweraveragepackets": 10 /* faster response */
|
|
@@ -470,7 +470,7 @@ describe( "record", function() {
|
|
|
470
470
|
server.close()
|
|
471
471
|
|
|
472
472
|
let stats = fs.statSync( "/tmp/dualrecordingpower.wav" )
|
|
473
|
-
expect( stats.size ).to.be.within(
|
|
473
|
+
expect( stats.size ).to.be.within( 30000 , 40000 )
|
|
474
474
|
|
|
475
475
|
stats = fs.statSync( "/tmp/dualrecording.wav" )
|
|
476
476
|
expect( stats.size ).to.be.within( 110000, 190000 )
|
|
@@ -4,9 +4,76 @@
|
|
|
4
4
|
const expect = require( "chai" ).expect
|
|
5
5
|
const projectrtp = require( "../../index.js" ).projectrtp
|
|
6
6
|
|
|
7
|
+
const fs = require( "node:fs" ).promises
|
|
8
|
+
const dgram = require( "dgram" )
|
|
9
|
+
const rtp = require( "../util/rtp" )
|
|
10
|
+
|
|
7
11
|
describe( "tonegen", function() {
|
|
12
|
+
|
|
13
|
+
const silentfilename = "/tmp/silent.wav"
|
|
14
|
+
|
|
15
|
+
this.afterEach( async () => {
|
|
16
|
+
try{
|
|
17
|
+
await fs.unlink( silentfilename )
|
|
18
|
+
} catch( e ) { /* silent */ }
|
|
19
|
+
|
|
20
|
+
} )
|
|
21
|
+
|
|
8
22
|
it( "tone.generate exists", async function() {
|
|
9
23
|
expect( projectrtp.tone.generate ).to.be.an( "function" )
|
|
10
24
|
} )
|
|
25
|
+
|
|
26
|
+
it( "generate silence and ensure looped is silent", async function() {
|
|
27
|
+
|
|
28
|
+
this.timeout( 4000 )
|
|
29
|
+
this.slow( 3000 )
|
|
30
|
+
|
|
31
|
+
/* Trying to replicate a bug where we use the silence in a tone file to send silence */
|
|
32
|
+
projectrtp.tone.generate( "350+440*0.5:1000", silentfilename )
|
|
33
|
+
projectrtp.tone.generate( "400+450*0.5/0/400+450*0.5/0:400/200/400/2000", silentfilename )
|
|
34
|
+
projectrtp.tone.generate( "697+1209*0.5/0/697+1336*0.5/0/697+1477*0.5/0/697+1633*0.5/0:400/100", silentfilename )
|
|
35
|
+
|
|
36
|
+
const server = dgram.createSocket( "udp4" )
|
|
37
|
+
|
|
38
|
+
let done
|
|
39
|
+
const complete = new Promise( resolve => done = resolve )
|
|
40
|
+
let recvcount = 0
|
|
41
|
+
let allaregood = true
|
|
42
|
+
server.on( "message", function( dgm ) {
|
|
43
|
+
// check
|
|
44
|
+
const parsed = rtp.parsepk( dgm )
|
|
45
|
+
|
|
46
|
+
recvcount++
|
|
47
|
+
|
|
48
|
+
allaregood &&= Array.from( parsed.payload ).every( val => 255 === val )
|
|
49
|
+
|
|
50
|
+
if( 100 < recvcount ) channel.close()
|
|
51
|
+
} )
|
|
52
|
+
|
|
53
|
+
server.bind()
|
|
54
|
+
await new Promise( resolve => server.on( "listening", resolve() ) )
|
|
55
|
+
|
|
56
|
+
const ourport = server.address().port
|
|
57
|
+
|
|
58
|
+
const chandef = { "remote": { "address": "localhost", "port": ourport, "codec": 0 } }
|
|
59
|
+
const channel = await projectrtp.openchannel( chandef, function( d ) {
|
|
60
|
+
if( "close" === d.action ) {
|
|
61
|
+
server.close()
|
|
62
|
+
done()
|
|
63
|
+
}
|
|
64
|
+
} )
|
|
65
|
+
|
|
66
|
+
const prompt = { "wav": silentfilename, "start": 2100, "stop": 3100, "loop": 3 } //silent
|
|
67
|
+
const soup = {
|
|
68
|
+
"files": [ prompt ], "interupt": true
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
channel.play( soup )
|
|
72
|
+
|
|
73
|
+
await complete
|
|
74
|
+
|
|
75
|
+
expect( allaregood ).to.be.true
|
|
76
|
+
|
|
77
|
+
} )
|
|
11
78
|
} )
|
|
12
79
|
|