@babblevoice/projectrtp 2.4.1 → 2.4.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/.github/workflows/buildimage.yaml +16 -5
- package/lib/node.js +1 -1
- package/lib/server.js +1 -1
- package/package.json +3 -2
- package/src/projectrtpchannel.cpp +5 -25
- package/src/projectrtpchannel.h +9 -3
- package/src/projectrtpnodemain.cpp +1 -1
- package/test/basictests.js +30 -0
- package/test/interface/projectrtpdtmf.js +208 -109
- package/test/interface/projectrtprecord.js +6 -14
|
@@ -6,13 +6,11 @@ on:
|
|
|
6
6
|
push:
|
|
7
7
|
branches:
|
|
8
8
|
- 'main'
|
|
9
|
-
- 'dev'
|
|
10
9
|
tags:
|
|
11
10
|
- 'v*.*.*'
|
|
12
11
|
pull_request:
|
|
13
12
|
branches:
|
|
14
13
|
- 'main'
|
|
15
|
-
- 'dev'
|
|
16
14
|
|
|
17
15
|
#GH
|
|
18
16
|
permissions:
|
|
@@ -27,17 +25,30 @@ jobs:
|
|
|
27
25
|
uses: actions/checkout@v3
|
|
28
26
|
# https://github.com/docker/setup-qemu-action
|
|
29
27
|
- name: Set up QEMU
|
|
30
|
-
uses: docker/setup-qemu-action@
|
|
28
|
+
uses: docker/setup-qemu-action@v2
|
|
31
29
|
# https://github.com/docker/setup-buildx-action
|
|
32
30
|
- name: Set up Docker Buildx
|
|
33
31
|
id: buildx
|
|
34
|
-
uses: docker/setup-buildx-action@v2
|
|
32
|
+
uses: docker/setup-buildx-action@v2
|
|
35
33
|
- name: Login to Docker Hub
|
|
36
34
|
if: github.event_name != 'pull_request'
|
|
37
35
|
uses: docker/login-action@v2
|
|
38
36
|
with:
|
|
39
37
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
40
38
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
39
|
+
|
|
40
|
+
- name: Build and export to Docker
|
|
41
|
+
uses: docker/build-push-action@v4
|
|
42
|
+
with:
|
|
43
|
+
context: .
|
|
44
|
+
load: true
|
|
45
|
+
tags: docker.io/tinpotnick/projectrtp:test
|
|
46
|
+
|
|
47
|
+
- name: Test
|
|
48
|
+
# Use --exit so we don't hang a test on exception
|
|
49
|
+
run: |
|
|
50
|
+
docker run --rm docker.io/tinpotnick/projectrtp:test /bin/sh -c 'npm run github:check'
|
|
51
|
+
|
|
41
52
|
- name: Docker meta
|
|
42
53
|
id: ourdockertags
|
|
43
54
|
uses: docker/metadata-action@v3
|
|
@@ -56,7 +67,7 @@ jobs:
|
|
|
56
67
|
type=sha
|
|
57
68
|
|
|
58
69
|
- name: Build and push
|
|
59
|
-
uses: docker/build-push-action@
|
|
70
|
+
uses: docker/build-push-action@v4
|
|
60
71
|
with:
|
|
61
72
|
context: .
|
|
62
73
|
platforms: linux/amd64,linux/arm64
|
package/lib/node.js
CHANGED
|
@@ -117,7 +117,7 @@ class rtpnode {
|
|
|
117
117
|
* @returns { void }
|
|
118
118
|
*/
|
|
119
119
|
_onsocketconnect( /* sock */ ) {
|
|
120
|
-
console.log( "Connected to " + this.host + ":" + this.port )
|
|
120
|
+
//console.log( "Connected to " + this.host + ":" + this.port )
|
|
121
121
|
this.send( {}, this.connection )
|
|
122
122
|
this._onsocketreadypromiseresolve( this )
|
|
123
123
|
this._reconnecttime = 500 /* mS */
|
package/lib/server.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babblevoice/projectrtp",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.3",
|
|
4
4
|
"description": "A scalable Node addon RTP server",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"test": "test"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"test": "./node_modules/mocha/bin/_mocha
|
|
12
|
+
"test": "./node_modules/mocha/bin/_mocha test/**/*.js --check-leaks",
|
|
13
|
+
"github:check": "node test/basictests.js; npm update; npm test",
|
|
13
14
|
"check": "tsc --checkJs --noEmit --target es6 --module commonjs --skipLibCheck *.js test/**/*.js; ./node_modules/eslint/bin/eslint.js ./",
|
|
14
15
|
"docs": "jsdoc -c jsdoc.conf.json ./README.md",
|
|
15
16
|
"stress": "node stress/index.js",
|
|
@@ -652,40 +652,20 @@ bool projectrtpchannel::checkfordtmf( rtppacket *src ) {
|
|
|
652
652
|
uint8_t event = pl[ 0 ] & 0x7f;
|
|
653
653
|
|
|
654
654
|
if( event <= 16 ) {
|
|
655
|
-
bool sendteleevent = false;
|
|
656
|
-
bool start = false;
|
|
657
|
-
|
|
658
655
|
/* Test for start */
|
|
659
|
-
if( 0 == endbit
|
|
660
|
-
0 == this->lasttelephoneeventsn ) {
|
|
661
|
-
start = true;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
if( 0 == endbit &&
|
|
665
|
-
0 != this->lasttelephoneeventsn &&
|
|
666
|
-
event != this->lasttelephoneevent
|
|
667
|
-
) {
|
|
668
|
-
/* Did we lose the last end of event */
|
|
669
|
-
this->lasttelephoneeventsn = 0;
|
|
670
|
-
sendteleevent = true;
|
|
671
|
-
} else if( 1 == endbit &&
|
|
672
|
-
0 != this->lasttelephoneeventsn ) {
|
|
673
|
-
sendteleevent = true;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
if( sendteleevent ) this->sendtelevent();
|
|
677
|
-
|
|
678
|
-
if( start ) {
|
|
656
|
+
if( 0 == endbit ) {
|
|
679
657
|
this->lasttelephoneeventsn = sn;
|
|
680
658
|
this->lasttelephoneevent = event;
|
|
681
|
-
} else if( 1 == endbit
|
|
659
|
+
} else if( 1 == endbit &&
|
|
660
|
+
0 != this->lasttelephoneeventsn ) {
|
|
682
661
|
this->lasttelephoneeventsn = 0;
|
|
662
|
+
this->sendtelevent();
|
|
683
663
|
}
|
|
684
664
|
}
|
|
685
665
|
}
|
|
686
666
|
return true;
|
|
687
667
|
} else if( 0 != this->lasttelephoneeventsn &&
|
|
688
|
-
abs( static_cast< long long int >( sn - this->lasttelephoneeventsn ) ) > MAXDTMFSNDIFFERENCE ) {
|
|
668
|
+
abs( static_cast< long long int > ( sn - this->lasttelephoneeventsn ) ) > MAXDTMFSNDIFFERENCE ) {
|
|
689
669
|
/* timeout on waiting for end packet */
|
|
690
670
|
this->sendtelevent();
|
|
691
671
|
this->lasttelephoneeventsn = 0;
|
package/src/projectrtpchannel.h
CHANGED
|
@@ -40,10 +40,16 @@ class projectchannelmux;
|
|
|
40
40
|
#define OUTBUFFERPACKETCOUNT 16
|
|
41
41
|
|
|
42
42
|
/*
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
The SN difference between receiving the first DTMF EV and when we consider we have lost all end events.
|
|
44
|
+
Delay = MAXDTMFSNDIFFERENCE * 20mS
|
|
45
|
+
|
|
46
|
+
rfc2833 - 3.6: An audio source SHOULD start transmitting event packets as soon as it
|
|
47
|
+
recognizes an event and every 50 ms thereafter or the packet interval
|
|
48
|
+
for the audio codec used for this session, if known.
|
|
49
|
+
This means our ts will not stay in sync with our sequence number - which increments
|
|
50
|
+
with every packet.
|
|
45
51
|
*/
|
|
46
|
-
#define MAXDTMFSNDIFFERENCE
|
|
52
|
+
#define MAXDTMFSNDIFFERENCE 6
|
|
47
53
|
|
|
48
54
|
|
|
49
55
|
/*
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const prtp = require( "../index.js" )
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Very basic test - to run in release workflow before we install
|
|
7
|
+
* dev dependancies - i.e. check we can run without dev dependancies.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Test open a channel.
|
|
12
|
+
*/
|
|
13
|
+
async function testopen() {
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const chan = await prtp.projectrtp.openchannel()
|
|
17
|
+
|
|
18
|
+
try{
|
|
19
|
+
if( !chan ) throw new Error( "Bad channel" )
|
|
20
|
+
if( "number" !== typeof chan.local.port ) throw new Error( "Port doesn't look correct" )
|
|
21
|
+
} finally {
|
|
22
|
+
chan.close()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
prtp.projectrtp.run()
|
|
27
|
+
testopen()
|
|
28
|
+
prtp.projectrtp.shutdown()
|
|
29
|
+
|
|
30
|
+
|
|
@@ -24,7 +24,7 @@ function sendpayload( sendtime, pk, dstport, server ) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/* helper functions */
|
|
27
|
-
function sendpk( sn, sendtime, dstport, server, pt = 0,
|
|
27
|
+
function sendpk( sn, ts, sendtime, dstport, server, pt = 0, ssrc ) {
|
|
28
28
|
|
|
29
29
|
if( !ssrc ) ssrc = 25
|
|
30
30
|
const pklength = 172
|
|
@@ -34,8 +34,6 @@ function sendpk( sn, sendtime, dstport, server, pt = 0, ts, ssrc ) {
|
|
|
34
34
|
const payload = Buffer.alloc( pklength - 12 ).fill( projectrtp.codecx.linear162pcmu( sn ) & 0xff )
|
|
35
35
|
const subheader = Buffer.alloc( 10 )
|
|
36
36
|
|
|
37
|
-
if( !ts ) ts = sn * 160
|
|
38
|
-
|
|
39
37
|
subheader.writeUInt8( pt, 1 ) // payload type
|
|
40
38
|
subheader.writeUInt16BE( ( sn ) % ( 2**16 ) )
|
|
41
39
|
subheader.writeUInt32BE( ts, 2 )
|
|
@@ -121,15 +119,15 @@ describe( "dtmf", function() {
|
|
|
121
119
|
|
|
122
120
|
/* send a packet every 20mS x 50 */
|
|
123
121
|
for( let i = 0; 23 > i; i ++ ) {
|
|
124
|
-
sendpk( i, i*20, channel.local.port, server )
|
|
122
|
+
sendpk( i, i*160, i*20, channel.local.port, server )
|
|
125
123
|
}
|
|
126
124
|
|
|
127
|
-
senddtmf( 23, 22
|
|
128
|
-
senddtmf( 24, 22
|
|
129
|
-
senddtmf( 25, 22
|
|
125
|
+
senddtmf( 23, 22*160, 23*20, channel.local.port, server, false, "4" )
|
|
126
|
+
senddtmf( 24, 22*160, 24*20, channel.local.port, server, false, "4" )
|
|
127
|
+
senddtmf( 25, 22*160, 25*20, channel.local.port, server, true, "4" )
|
|
130
128
|
|
|
131
129
|
for( let i = 26; 40 > i; i ++ ) {
|
|
132
|
-
sendpk( i, (i-3)*20, channel.local.port, server )
|
|
130
|
+
sendpk( i, i*160, (i-3)*20, channel.local.port, server )
|
|
133
131
|
}
|
|
134
132
|
|
|
135
133
|
setTimeout( () => channel.close(), 1000 )
|
|
@@ -180,7 +178,7 @@ describe( "dtmf", function() {
|
|
|
180
178
|
|
|
181
179
|
/* send a packet every 20mS x 50 */
|
|
182
180
|
for( let i = 0; 50 > i; i ++ ) {
|
|
183
|
-
sendpk( i, i*20, channel.local.port, server )
|
|
181
|
+
sendpk( i, i*160, i*20, channel.local.port, server )
|
|
184
182
|
}
|
|
185
183
|
|
|
186
184
|
setTimeout( () => channel.dtmf( "#1" ), 400 )
|
|
@@ -239,7 +237,7 @@ describe( "dtmf", function() {
|
|
|
239
237
|
|
|
240
238
|
/* send a packet every 20mS x 70 */
|
|
241
239
|
for( let i = 0; 50 > i; i ++ ) {
|
|
242
|
-
sendpk( i, i*20, channela.local.port, clienta )
|
|
240
|
+
sendpk( i, i*160, i*20, channela.local.port, clienta )
|
|
243
241
|
}
|
|
244
242
|
|
|
245
243
|
await new Promise( ( resolve ) => { setTimeout( () => resolve(), 400 ) } )
|
|
@@ -322,7 +320,7 @@ describe( "dtmf", function() {
|
|
|
322
320
|
|
|
323
321
|
/* send a packet every 20mS x 50 */
|
|
324
322
|
for( let i = 0; 50 > i; i ++ ) {
|
|
325
|
-
sendpk( i, i*20, channela.local.port, clienta )
|
|
323
|
+
sendpk( i, i*160, i*20, channela.local.port, clienta )
|
|
326
324
|
}
|
|
327
325
|
|
|
328
326
|
await new Promise( ( resolve ) => { setTimeout( () => resolve(), 100 ) } )
|
|
@@ -375,7 +373,7 @@ describe( "dtmf", function() {
|
|
|
375
373
|
|
|
376
374
|
/* send a packet every 20mS x 50 */
|
|
377
375
|
for( let i = 0; 13 > i; i ++ ) {
|
|
378
|
-
sendpk( i, i*20, channel.local.port, server )
|
|
376
|
+
sendpk( i, i*160, i*20, channel.local.port, server )
|
|
379
377
|
}
|
|
380
378
|
|
|
381
379
|
senddtmf( 13, 12 * 160, 13*20, channel.local.port, server, false, "4" )
|
|
@@ -384,7 +382,7 @@ describe( "dtmf", function() {
|
|
|
384
382
|
// senddtmf( 15, 12 * 160, 15*20, channel.port, server, true, "4" )
|
|
385
383
|
|
|
386
384
|
for( let i = 16; 23 > i; i ++ ) {
|
|
387
|
-
sendpk( i, (i-3)*20, channel.local.port, server )
|
|
385
|
+
sendpk( i, i*160, (i-3)*20, channel.local.port, server )
|
|
388
386
|
}
|
|
389
387
|
|
|
390
388
|
senddtmf( 23, 22 * 160, 23*20, channel.local.port, server, false, "5" )
|
|
@@ -392,7 +390,7 @@ describe( "dtmf", function() {
|
|
|
392
390
|
senddtmf( 25, 22 * 160, 25*20, channel.local.port, server, true, "5" )
|
|
393
391
|
|
|
394
392
|
for( let i = 26; 33 > i; i ++ ) {
|
|
395
|
-
sendpk( i, (i-6)*20, channel.local.port, server )
|
|
393
|
+
sendpk( i, i*160, (i-6)*20, channel.local.port, server )
|
|
396
394
|
}
|
|
397
395
|
|
|
398
396
|
setTimeout( () => channel.close(), 1000 )
|
|
@@ -432,20 +430,43 @@ describe( "dtmf", function() {
|
|
|
432
430
|
expect( channel.echo() ).to.be.true
|
|
433
431
|
|
|
434
432
|
/* send a packet every 20mS x 50 */
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
433
|
+
sendpk( 0, 160, 0, channel.local.port, server )
|
|
434
|
+
sendpk( 1, 1*160, 1*20, channel.local.port, server )
|
|
435
|
+
sendpk( 2, 2*160, 2*20, channel.local.port, server )
|
|
436
|
+
sendpk( 3, 3*160, 3*20, channel.local.port, server )
|
|
437
|
+
sendpk( 4, 4*160, 4*20, channel.local.port, server )
|
|
438
|
+
sendpk( 5, 5*160, 5*20, channel.local.port, server )
|
|
439
|
+
sendpk( 6, 6*160, 6*20, channel.local.port, server )
|
|
440
|
+
sendpk( 7, 7*160, 7*20, channel.local.port, server )
|
|
441
|
+
sendpk( 8, 8*160, 8*20, channel.local.port, server )
|
|
442
|
+
sendpk( 9, 9*160, 9*20, channel.local.port, server )
|
|
443
|
+
sendpk( 10, 10*160, 10*20, channel.local.port, server )
|
|
444
|
+
sendpk( 11, 11*160, 11*20, channel.local.port, server )
|
|
445
|
+
sendpk( 12, 12*160, 12*20, channel.local.port, server )
|
|
446
|
+
|
|
447
|
+
senddtmf( 13, 13*160, 13*20, channel.local.port, server, false, "4" )
|
|
448
|
+
sendpk( 14, 13*160, 13*20, channel.local.port, server, 0 )
|
|
449
|
+
sendpk( 15, 14*160, 14*20, channel.local.port, server, 0 )
|
|
450
|
+
|
|
451
|
+
senddtmf( 16, (15*160)+10, (15*20)+10, channel.local.port, server, false, "4" )
|
|
452
|
+
sendpk( 17, 15*160, 15*20, channel.local.port, server, 0 )
|
|
453
|
+
sendpk( 18, 16*160, 16*20, channel.local.port, server, 0 )
|
|
441
454
|
// Packet loss
|
|
442
|
-
// senddtmf(
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
455
|
+
// senddtmf( 19, (16*160)+20, (16*20)+20, channel.local.port, server, true, "4" )
|
|
456
|
+
|
|
457
|
+
sendpk( 20, 17*160, 17*20, channel.local.port, server, 0 )
|
|
458
|
+
sendpk( 21, 18*160, 18*20, channel.local.port, server, 0 )
|
|
459
|
+
sendpk( 22, 19*160, 19*20, channel.local.port, server, 0 )
|
|
460
|
+
sendpk( 23, 20*160, 20*20, channel.local.port, server, 0 )
|
|
461
|
+
sendpk( 24, 21*160, 21*20, channel.local.port, server, 0 )
|
|
462
|
+
sendpk( 25, 22*160, 22*20, channel.local.port, server, 0 )
|
|
463
|
+
sendpk( 26, 23*160, 23*20, channel.local.port, server, 0 )
|
|
464
|
+
sendpk( 27, 24*160, 24*20, channel.local.port, server, 0 )
|
|
465
|
+
sendpk( 28, 25*160, 25*20, channel.local.port, server, 0 )
|
|
466
|
+
sendpk( 29, 26*160, 26*20, channel.local.port, server, 0 )
|
|
467
|
+
sendpk( 30, 27*160, 27*20, channel.local.port, server, 0 )
|
|
447
468
|
|
|
448
|
-
setTimeout( () => channel.close(),
|
|
469
|
+
setTimeout( () => channel.close(), 1000 )
|
|
449
470
|
|
|
450
471
|
} )
|
|
451
472
|
|
|
@@ -456,7 +477,7 @@ describe( "dtmf", function() {
|
|
|
456
477
|
{ action: "close" }
|
|
457
478
|
]
|
|
458
479
|
|
|
459
|
-
expect( receviedpkcount ).to.be.above(
|
|
480
|
+
expect( receviedpkcount ).to.be.above( 15 )
|
|
460
481
|
expect( receivedmessages.length ).to.equal( 2 )
|
|
461
482
|
expect( receivedmessages[ 0 ] ).to.deep.include( expectedmessages[ 0 ] )
|
|
462
483
|
expect( receivedmessages[ 1 ] ).to.deep.include( expectedmessages[ 1 ] )
|
|
@@ -521,27 +542,62 @@ describe( "dtmf", function() {
|
|
|
521
542
|
expect( channela.mix( channelb ) ).to.be.true
|
|
522
543
|
|
|
523
544
|
/* send a packet every 20mS x 50 */
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
senddtmf(
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
+
sendpk( 0, 0, 0, channela.local.port, endpointa )
|
|
546
|
+
sendpk( 1, 1*160, 1*20, channela.local.port, endpointa )
|
|
547
|
+
sendpk( 2, 2*160, 2*20, channela.local.port, endpointa )
|
|
548
|
+
sendpk( 3, 3*160, 3*20, channela.local.port, endpointa )
|
|
549
|
+
sendpk( 4, 4*160, 4*20, channela.local.port, endpointa )
|
|
550
|
+
sendpk( 5, 5*160, 5*20, channela.local.port, endpointa )
|
|
551
|
+
sendpk( 6, 6*160, 6*20, channela.local.port, endpointa )
|
|
552
|
+
sendpk( 7, 7*160, 7*20, channela.local.port, endpointa )
|
|
553
|
+
sendpk( 8, 8*160, 8*20, channela.local.port, endpointa )
|
|
554
|
+
sendpk( 9, 9*160, 9*20, channela.local.port, endpointa )
|
|
555
|
+
sendpk( 10, 10*160, 10*20, channela.local.port, endpointa )
|
|
556
|
+
sendpk( 11, 11*160, 11*20, channela.local.port, endpointa )
|
|
557
|
+
sendpk( 12, 12*160, 12*20, channela.local.port, endpointa )
|
|
558
|
+
|
|
559
|
+
senddtmf( 13, 13*160, 13*20, channela.local.port, endpointa, false, "4" )
|
|
560
|
+
sendpk( 14, 13*160, 13*20, channela.local.port, endpointa, 0 )
|
|
561
|
+
sendpk( 15, 14*160, 14*20, channela.local.port, endpointa, 0 )
|
|
562
|
+
senddtmf( 16, (15*160)+10, (15*20)+10, channela.local.port, endpointa, false, "4" )
|
|
563
|
+
sendpk( 17, 15*160, 15*20, channela.local.port, endpointa, 0 )
|
|
564
|
+
sendpk( 18, 16*160, 16*20, channela.local.port, endpointa, 0 )
|
|
565
|
+
senddtmf( 19, (17*160)+20, (17*20)+20, channela.local.port, endpointa, true, "4" )
|
|
566
|
+
sendpk( 20, 17*160, 17*20, channela.local.port, endpointa, 0 )
|
|
567
|
+
sendpk( 21, 18*160, 18*20, channela.local.port, endpointa, 0 )
|
|
568
|
+
senddtmf( 22, (18*160)+30, (18*20)+30, channela.local.port, endpointa, true, "4" )
|
|
569
|
+
sendpk( 23, 19*160, 19*20, channela.local.port, endpointa, 0 )
|
|
570
|
+
sendpk( 24, 20*160, 20*20, channela.local.port, endpointa, 0 )
|
|
571
|
+
sendpk( 25, 21*160, 21*20, channela.local.port, endpointa, 0 )
|
|
572
|
+
sendpk( 26, 22*160, 22*20, channela.local.port, endpointa, 0 )
|
|
573
|
+
sendpk( 27, 23*160, 23*20, channela.local.port, endpointa, 0 )
|
|
574
|
+
sendpk( 28, 24*160, 24*20, channela.local.port, endpointa, 0 )
|
|
575
|
+
sendpk( 29, 25*160, 25*20, channela.local.port, endpointa, 0 )
|
|
576
|
+
|
|
577
|
+
senddtmf( 30, 26*160, 26*20, channela.local.port, endpointa, false, "5" )
|
|
578
|
+
sendpk( 31, 26*160, 26*20, channela.local.port, endpointa, 0 )
|
|
579
|
+
sendpk( 32, 27*160, 27*20, channela.local.port, endpointa, 0 )
|
|
580
|
+
senddtmf( 33, (27*160)+10, (27*20)+10, channela.local.port, endpointa, false, "5" )
|
|
581
|
+
sendpk( 34, 28*160, 28*20, channela.local.port, endpointa, 0 )
|
|
582
|
+
sendpk( 35, 29*160, 28*20, channela.local.port, endpointa, 0 )
|
|
583
|
+
senddtmf( 36, (28*160)+20, (28*20)+20, channela.local.port, endpointa, true, "5" )
|
|
584
|
+
sendpk( 37, 30*160, 29*20, channela.local.port, endpointa, 0 )
|
|
585
|
+
sendpk( 38, 31*160, 30*20, channela.local.port, endpointa, 0 )
|
|
586
|
+
|
|
587
|
+
senddtmf( 39, (38*160)+30, (30*20)+30, channela.local.port, endpointa, true, "5" )
|
|
588
|
+
sendpk( 40, 32*160, 31*20, channela.local.port, endpointa, 0 )
|
|
589
|
+
sendpk( 41, 33*160, 32*20, channela.local.port, endpointa, 0 )
|
|
590
|
+
|
|
591
|
+
sendpk( 42, 34*160, 33*20, channela.local.port, endpointa, 0 )
|
|
592
|
+
sendpk( 43, 35*160, 34*20, channela.local.port, endpointa, 0 )
|
|
593
|
+
sendpk( 44, 36*160, 35*20, channela.local.port, endpointa, 0 )
|
|
594
|
+
sendpk( 45, 37*160, 36*20, channela.local.port, endpointa, 0 )
|
|
595
|
+
sendpk( 46, 38*160, 37*20, channela.local.port, endpointa, 0 )
|
|
596
|
+
sendpk( 47, 39*160, 38*20, channela.local.port, endpointa, 0 )
|
|
597
|
+
sendpk( 48, 40*160, 39*20, channela.local.port, endpointa, 0 )
|
|
598
|
+
sendpk( 49, 51*160, 40*20, channela.local.port, endpointa, 0 )
|
|
599
|
+
|
|
600
|
+
await new Promise( ( r ) => { setTimeout( () => r(), 1400 ) } )
|
|
545
601
|
|
|
546
602
|
channela.close()
|
|
547
603
|
endpointa.close()
|
|
@@ -551,22 +607,20 @@ describe( "dtmf", function() {
|
|
|
551
607
|
|
|
552
608
|
expect( endpointapkcount ).to.be.within( 30, 51 )
|
|
553
609
|
expect( endpointbpkcount ).to.be.within( 30, 51 )
|
|
554
|
-
expect( dtmfpkcount ).to.
|
|
555
|
-
|
|
556
|
-
const expectedmessages = [
|
|
557
|
-
{ action: "mix", event: "start" },
|
|
558
|
-
{ action: "telephone-event", event: "4" },
|
|
559
|
-
{ action: "telephone-event", event: "5" },
|
|
560
|
-
{ action: "mix", event: "finished" },
|
|
561
|
-
{ action: "close" }
|
|
562
|
-
]
|
|
610
|
+
expect( dtmfpkcount ).to.be.within( 4, 8 )
|
|
563
611
|
|
|
564
612
|
expect( receivedmessages.length ).to.equal( 5 )
|
|
565
|
-
|
|
566
|
-
expect( receivedmessages[
|
|
567
|
-
expect( receivedmessages[
|
|
568
|
-
expect( receivedmessages[
|
|
569
|
-
expect( receivedmessages[
|
|
613
|
+
|
|
614
|
+
expect( receivedmessages[ 0 ].action ).to.equal( "mix" )
|
|
615
|
+
expect( receivedmessages[ 1 ].action ).to.equal( "telephone-event" )
|
|
616
|
+
expect( receivedmessages[ 2 ].action ).to.equal( "telephone-event" )
|
|
617
|
+
expect( receivedmessages[ 3 ].action ).to.equal( "mix" )
|
|
618
|
+
expect( receivedmessages[ 4 ].action ).to.equal( "close" )
|
|
619
|
+
|
|
620
|
+
expect( receivedmessages[ 0 ].event ).to.equal( "start" )
|
|
621
|
+
expect( receivedmessages[ 1 ].event ).to.equal( "4" )
|
|
622
|
+
expect( receivedmessages[ 2 ].event ).to.equal( "5" )
|
|
623
|
+
expect( receivedmessages[ 3 ].event ).to.equal( "finished" )
|
|
570
624
|
|
|
571
625
|
} )
|
|
572
626
|
|
|
@@ -656,25 +710,70 @@ describe( "dtmf", function() {
|
|
|
656
710
|
expect( channela.mix( channelc ) ).to.be.true
|
|
657
711
|
|
|
658
712
|
/* send a packet every 20mS x 50 */
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
713
|
+
/* NO FOR LOOPS for explicit readablity of the test */
|
|
714
|
+
sendpk( 0, 0, 0, channela.local.port, endpointa )
|
|
715
|
+
sendpk( 1, 1*160, 20, channela.local.port, endpointa )
|
|
716
|
+
sendpk( 2, 2*160, 2*20, channela.local.port, endpointa )
|
|
717
|
+
sendpk( 3, 3*160, 3*20, channela.local.port, endpointa )
|
|
718
|
+
sendpk( 4, 4*160, 4*20, channela.local.port, endpointa )
|
|
719
|
+
sendpk( 5, 5*160, 5*20, channela.local.port, endpointa )
|
|
720
|
+
sendpk( 6, 6*160, 6*20, channela.local.port, endpointa )
|
|
721
|
+
sendpk( 7, 7*160, 7*20, channela.local.port, endpointa )
|
|
722
|
+
sendpk( 8, 8*160, 8*20, channela.local.port, endpointa )
|
|
723
|
+
sendpk( 9, 9*160, 9*20, channela.local.port, endpointa )
|
|
724
|
+
sendpk( 10, 10*160, 10*20, channela.local.port, endpointa )
|
|
725
|
+
sendpk( 11, 11*160, 11*20, channela.local.port, endpointa )
|
|
726
|
+
sendpk( 12, 12*160, 12*20, channela.local.port, endpointa )
|
|
727
|
+
|
|
728
|
+
/* rfc2833 - 3.6: An audio source SHOULD start transmitting event packets as soon as it
|
|
729
|
+
recognizes an event and every 50 ms thereafter or the packet interval
|
|
730
|
+
for the audio codec used for this session, if known.
|
|
731
|
+
This means our ts will not stay in sync with our sequence number - which increments
|
|
732
|
+
with every packet.
|
|
733
|
+
senddtmf( sn, ts, sendtime, port, socket, endofevent, event )
|
|
734
|
+
sendpk( sn, sendtime, port, socket, pt, ts, ssrc ) */
|
|
735
|
+
senddtmf( 13, 13*160, 13*20, channela.local.port, endpointa, false, "4" )
|
|
736
|
+
sendpk( 14, 13*160, 13*20, channela.local.port, endpointa, 0 )
|
|
737
|
+
sendpk( 15, 14*160, 14*20, channela.local.port, endpointa, 0 )
|
|
738
|
+
senddtmf( 16, (16*160), (13*20)+50, channela.local.port, endpointa, false, "4" )
|
|
739
|
+
sendpk( 17, 15*160, 15*20, channela.local.port, endpointa, 0 )
|
|
740
|
+
sendpk( 18, 16*160, 16*20, channela.local.port, endpointa, 0 )
|
|
741
|
+
senddtmf( 19, (19*160), (13*20)+100, channela.local.port, endpointa, true, "4" )
|
|
742
|
+
sendpk( 20, 17*160, 17*20, channela.local.port, endpointa, 0 )
|
|
743
|
+
sendpk( 21, 18*160, 18*20, channela.local.port, endpointa, 0 )
|
|
744
|
+
senddtmf( 22, (22*160)+20, (13*20)+150, channela.local.port, endpointa, true, "4" )
|
|
745
|
+
sendpk( 23, 19*160, 19*20, channela.local.port, endpointa, 0 )
|
|
746
|
+
|
|
747
|
+
senddtmf( 24, 20*160, 20*20, channela.local.port, endpointa, false, "5" )
|
|
748
|
+
sendpk( 25, 20*160, 20*20, channela.local.port, endpointa, 0 )
|
|
749
|
+
sendpk( 26, 21*160, 21*20, channela.local.port, endpointa, 0 )
|
|
750
|
+
senddtmf( 27, (27*160), (20*20)+50, channela.local.port, endpointa, false, "5" )
|
|
751
|
+
sendpk( 28, 22*160, 22*20, channela.local.port, endpointa, 0 )
|
|
752
|
+
sendpk( 29, 23*160, 23*20, channela.local.port, endpointa, 0 )
|
|
753
|
+
senddtmf( 30, (30*160), (20*20)+100, channela.local.port, endpointa, true, "5" )
|
|
754
|
+
sendpk( 31, 24*160, 24*20, channela.local.port, endpointa, 0 )
|
|
755
|
+
sendpk( 32, 25*160, 25*20, channela.local.port, endpointa, 0 )
|
|
756
|
+
senddtmf( 33, (33*160), (20*20)+150, channela.local.port, endpointa, true, "5" )
|
|
757
|
+
sendpk( 34, 26*160, 26*20, channela.local.port, endpointa, 0 )
|
|
758
|
+
sendpk( 35, 27*160, 27*20, channela.local.port, endpointa, 0 )
|
|
759
|
+
sendpk( 36, 28*160, 28*20, channela.local.port, endpointa, 0 )
|
|
760
|
+
sendpk( 37, 29*160, 29*20, channela.local.port, endpointa, 0 )
|
|
761
|
+
sendpk( 38, 30*160, 30*20, channela.local.port, endpointa, 0 )
|
|
762
|
+
sendpk( 39, 31*160, 31*20, channela.local.port, endpointa, 0 )
|
|
763
|
+
sendpk( 40, 32*160, 32*20, channela.local.port, endpointa, 0 )
|
|
764
|
+
sendpk( 41, 33*160, 33*20, channela.local.port, endpointa, 0 )
|
|
765
|
+
sendpk( 42, 34*160, 34*20, channela.local.port, endpointa, 0 )
|
|
766
|
+
sendpk( 43, 35*160, 35*20, channela.local.port, endpointa, 0 )
|
|
767
|
+
sendpk( 44, 36*160, 36*20, channela.local.port, endpointa, 0 )
|
|
768
|
+
sendpk( 45, 37*160, 37*20, channela.local.port, endpointa, 0 )
|
|
769
|
+
sendpk( 46, 38*160, 38*20, channela.local.port, endpointa, 0 )
|
|
770
|
+
sendpk( 47, 39*160, 39*20, channela.local.port, endpointa, 0 )
|
|
771
|
+
sendpk( 48, 40*160, 40*20, channela.local.port, endpointa, 0 )
|
|
772
|
+
sendpk( 49, 41*160, 41*20, channela.local.port, endpointa, 0 )
|
|
773
|
+
sendpk( 50, 42*160, 42*20, channela.local.port, endpointa, 0 )
|
|
774
|
+
sendpk( 51, 43*160, 43*20, channela.local.port, endpointa, 0 )
|
|
775
|
+
sendpk( 52, 44*160, 44*20, channela.local.port, endpointa, 0 )
|
|
776
|
+
sendpk( 53, 45*160, 45*20, channela.local.port, endpointa, 0 )
|
|
678
777
|
|
|
679
778
|
await new Promise( ( resolve ) => { setTimeout( () => resolve(), 1200 ) } )
|
|
680
779
|
|
|
@@ -691,22 +790,22 @@ describe( "dtmf", function() {
|
|
|
691
790
|
|
|
692
791
|
// 3 after we return to the event loop and enter the callback with close event.
|
|
693
792
|
expect( dtmfapkcount ).to.equal( 0 )
|
|
694
|
-
expect( dtmfbpkcount ).to.
|
|
695
|
-
expect( dtmfcpkcount ).to.
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
]
|
|
793
|
+
expect( dtmfbpkcount ).to.be.within( 4, 8 )
|
|
794
|
+
expect( dtmfcpkcount ).to.be.within( 4, 8 )
|
|
795
|
+
|
|
796
|
+
expect( receveiedmessages[ 0 ].action ).to.equal( "mix" )
|
|
797
|
+
expect( receveiedmessages[ 1 ].action ).to.equal( "mix" )
|
|
798
|
+
expect( receveiedmessages[ 2 ].action ).to.equal( "telephone-event" )
|
|
799
|
+
expect( receveiedmessages[ 3 ].action ).to.equal( "telephone-event" )
|
|
800
|
+
expect( receveiedmessages[ 4 ].action ).to.equal( "mix" )
|
|
801
|
+
expect( receveiedmessages[ 5 ].action ).to.equal( "close" )
|
|
802
|
+
|
|
803
|
+
expect( receveiedmessages[ 0 ].event ).to.equal( "start" )
|
|
804
|
+
expect( receveiedmessages[ 1 ].event ).to.equal( "start" )
|
|
805
|
+
expect( receveiedmessages[ 2 ].event ).to.equal( "4" )
|
|
806
|
+
expect( receveiedmessages[ 3 ].event ).to.equal( "5" )
|
|
807
|
+
expect( receveiedmessages[ 4 ].event ).to.equal( "finished" )
|
|
705
808
|
|
|
706
|
-
for( let i = 0; i < expectedmessages.length; i++ ) {
|
|
707
|
-
expect( expectedmessages[ i ].action ).to.equal( receveiedmessages[ i ].action )
|
|
708
|
-
if( expectedmessages[ i ].event ) expect( receveiedmessages[ i ].event ).to.equal( receveiedmessages[ i ].event )
|
|
709
|
-
}
|
|
710
809
|
} )
|
|
711
810
|
|
|
712
811
|
it( "DTMF captured not working", async function() {
|
|
@@ -747,29 +846,29 @@ describe( "dtmf", function() {
|
|
|
747
846
|
|
|
748
847
|
// Event "3"
|
|
749
848
|
const dstport = channel.local.port
|
|
750
|
-
sendpk( 948, 0, dstport, server, 0,
|
|
849
|
+
sendpk( 948, 148480, 0, dstport, server, 0, 518218235 )
|
|
751
850
|
sendpayload( 20, fromstr( "80 e5 03 b5 00 02 44 a0 1e e3 61 fb 03 0a 00 a0 4c d1" ), dstport, server )
|
|
752
|
-
sendpk( 950, 40, dstport, server, 0,
|
|
851
|
+
sendpk( 950, 148800, 40, dstport, server, 0, 518218235 )
|
|
753
852
|
sendpayload( 60, fromstr( "80 65 03 b7 00 02 44 a0 1e e3 61 fb 03 0a 01 40 25 b8" ), dstport, server )
|
|
754
|
-
sendpk( 952, 80, dstport, server, 0,
|
|
853
|
+
sendpk( 952, 149120, 80, dstport, server, 0, 518218235 )
|
|
755
854
|
sendpayload( 100, fromstr( "80 65 03 b9 00 02 44 a0 1e e3 61 fb 03 0a 01 e0 e8 81" ), dstport, server )
|
|
756
|
-
sendpk( 954, 120, dstport, server, 0,
|
|
855
|
+
sendpk( 954, 149440,120, dstport, server, 0, 518218235 )
|
|
757
856
|
sendpayload( 140, fromstr( "80 65 03 bb 00 02 44 a0 1e e3 61 fb 03 0a 02 80 e2 74" ), dstport, server )
|
|
758
|
-
sendpk( 956, 160, dstport, server, 0,
|
|
857
|
+
sendpk( 956, 149760, 160, dstport, server, 0, 518218235 )
|
|
759
858
|
sendpayload( 180, fromstr( "80 65 03 bd 00 02 44 a0 1e e3 61 fb 03 0a 03 20 1f bb" ), dstport, server )
|
|
760
|
-
sendpk( 958, 200, dstport, server, 0,
|
|
859
|
+
sendpk( 958, 150080, 200, dstport, server, 0, 518218235 )
|
|
761
860
|
sendpayload( 220, fromstr( "80 65 03 bf 00 02 44 a0 1e e3 61 fb 03 0a 03 c0 13 0c" ), dstport, server )
|
|
762
|
-
sendpk( 960, 240, dstport, server, 0,
|
|
861
|
+
sendpk( 960, 150400,240, dstport, server, 0, 518218235 )
|
|
763
862
|
sendpayload( 260, fromstr( "80 65 03 c1 00 02 44 a0 1e e3 61 fb 03 0a 04 60 2e bf" ), dstport, server )
|
|
764
|
-
sendpk( 962, 280, dstport, server, 0,
|
|
863
|
+
sendpk( 962, 150720, 280, dstport, server, 0, 518218235 )
|
|
765
864
|
sendpayload( 300, fromstr( "80 65 03 c3 00 02 44 a0 1e e3 61 fb 03 8a 04 60 05 c1" ), dstport, server )
|
|
766
865
|
sendpayload( 320 ,fromstr( "80 65 03 c4 00 02 44 a0 1e e3 61 fb 03 8a 04 60 bb 69" ), dstport, server )
|
|
767
|
-
sendpk( 965, 340, dstport, server, 0,
|
|
866
|
+
sendpk( 965, 151200, 340, dstport, server, 0, 518218235 )
|
|
768
867
|
sendpayload( 360, fromstr( "80 65 03 c6 00 02 44 a0 1e e3 61 fb 03 8a 04 60 1e 27" ), dstport, server )
|
|
769
|
-
sendpk( 967, 380, dstport, server, 0,
|
|
770
|
-
sendpk( 968, 400, dstport, server, 0,
|
|
771
|
-
sendpk( 969, 420, dstport, server, 0,
|
|
772
|
-
sendpk( 970, 440, dstport, server, 0,
|
|
868
|
+
sendpk( 967, 151520, 380, dstport, server, 0, 518218235 )
|
|
869
|
+
sendpk( 968, 151680, 400, dstport, server, 0, 518218235 )
|
|
870
|
+
sendpk( 969, 151840, 420, dstport, server, 0, 518218235 )
|
|
871
|
+
sendpk( 970, 152000, 440, dstport, server, 0, 518218235 )
|
|
773
872
|
|
|
774
873
|
setTimeout( () => channel.close(), 25*20 )
|
|
775
874
|
} )
|
|
@@ -90,6 +90,7 @@ describe( "record", function() {
|
|
|
90
90
|
|
|
91
91
|
await new Promise( ( resolve ) => { setTimeout( () => resolve(), 1300 ) } )
|
|
92
92
|
channel.close()
|
|
93
|
+
await new Promise( resolve => { server.on( "close", resolve ) } )
|
|
93
94
|
|
|
94
95
|
/* Now test the file */
|
|
95
96
|
const wavinfo = prtp.projectrtp.soundfile.info( "/tmp/ourrecording.wav" )
|
|
@@ -135,9 +136,6 @@ describe( "record", function() {
|
|
|
135
136
|
|
|
136
137
|
server.bind()
|
|
137
138
|
|
|
138
|
-
let done
|
|
139
|
-
const finished = new Promise( ( r ) => { done = r } )
|
|
140
|
-
|
|
141
139
|
let expectedmessagecount = 0
|
|
142
140
|
const expectedmessages = [
|
|
143
141
|
{ action: "record", file: "/tmp/ourstoppedrecording.wav", event: "recording" },
|
|
@@ -151,7 +149,6 @@ describe( "record", function() {
|
|
|
151
149
|
expect( d ).to.deep.include( expectedmessages[ expectedmessagecount ] )
|
|
152
150
|
expectedmessagecount++
|
|
153
151
|
if( "close" === d.action ) {
|
|
154
|
-
done()
|
|
155
152
|
server.close()
|
|
156
153
|
}
|
|
157
154
|
} )
|
|
@@ -175,7 +172,7 @@ describe( "record", function() {
|
|
|
175
172
|
|
|
176
173
|
await new Promise( ( resolve ) => { setTimeout( () => resolve(), 1300 ) } )
|
|
177
174
|
channel.close()
|
|
178
|
-
await
|
|
175
|
+
await new Promise( resolve => { server.on( "close", resolve ) } )
|
|
179
176
|
|
|
180
177
|
/* Now test the file */
|
|
181
178
|
const wavinfo = prtp.projectrtp.soundfile.info( "/tmp/ourstoppedrecording.wav" )
|
|
@@ -203,16 +200,12 @@ describe( "record", function() {
|
|
|
203
200
|
this.timeout( 1500 )
|
|
204
201
|
this.slow( 1200 )
|
|
205
202
|
|
|
206
|
-
let done
|
|
207
|
-
const finished = new Promise( ( r ) => { done = r } )
|
|
208
|
-
|
|
209
203
|
server.bind()
|
|
210
204
|
server.on( "listening", async function() {
|
|
211
205
|
|
|
212
206
|
channel = await prtp.projectrtp.openchannel( { "remote": { "address": "localhost", "port": server.address().port, "codec": 0 } }, function( d ) {
|
|
213
207
|
if( "close" === d.action ) {
|
|
214
208
|
server.close()
|
|
215
|
-
done()
|
|
216
209
|
}
|
|
217
210
|
} )
|
|
218
211
|
|
|
@@ -238,8 +231,7 @@ describe( "record", function() {
|
|
|
238
231
|
|
|
239
232
|
await new Promise( ( r ) => { setTimeout( () => r(), 1300 ) } )
|
|
240
233
|
channel.close()
|
|
241
|
-
|
|
242
|
-
await finished
|
|
234
|
+
await new Promise( resolve => { server.on( "close", resolve ) } )
|
|
243
235
|
|
|
244
236
|
/* Now test the file */
|
|
245
237
|
const wavinfo = prtp.projectrtp.soundfile.info( "/tmp/ourpausedrecording.wav" )
|
|
@@ -248,12 +240,12 @@ describe( "record", function() {
|
|
|
248
240
|
expect( wavinfo.samplerate ).to.equal( 8000 )
|
|
249
241
|
expect( wavinfo.byterate ).to.equal( 32000 )
|
|
250
242
|
expect( wavinfo.bitdepth ).to.equal( 16 )
|
|
251
|
-
expect( wavinfo.chunksize ).to.be.within(
|
|
243
|
+
expect( wavinfo.chunksize ).to.be.within( 2500, 7000 ) /* 200mS of audio */
|
|
252
244
|
expect( wavinfo.fmtchunksize ).to.equal( 16 )
|
|
253
|
-
expect( wavinfo.subchunksize ).to.be.within(
|
|
245
|
+
expect( wavinfo.subchunksize ).to.be.within( 2500, 7000 )
|
|
254
246
|
|
|
255
247
|
const stats = fs.statSync( "/tmp/ourpausedrecording.wav" )
|
|
256
|
-
expect( stats.size ).to.be.within(
|
|
248
|
+
expect( stats.size ).to.be.within( 2500, 7000 )
|
|
257
249
|
|
|
258
250
|
} )
|
|
259
251
|
|