@babblevoice/projectrtp 2.4.2 → 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.
@@ -47,7 +47,7 @@ jobs:
47
47
  - name: Test
48
48
  # Use --exit so we don't hang a test on exception
49
49
  run: |
50
- docker run --rm docker.io/tinpotnick/projectrtp:test /bin/sh -c 'npm update;./node_modules/mocha/bin/_mocha --recursive --check-leaks --exit'
50
+ docker run --rm docker.io/tinpotnick/projectrtp:test /bin/sh -c 'npm run github:check'
51
51
 
52
52
  - name: Docker meta
53
53
  id: ourdockertags
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babblevoice/projectrtp",
3
- "version": "2.4.2",
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 --recursive --check-leaks",
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;
@@ -40,10 +40,16 @@ class projectchannelmux;
40
40
  #define OUTBUFFERPACKETCOUNT 16
41
41
 
42
42
  /*
43
- The SN difference between receiving the first DTMF EV and when we consider we have lost all end events.
44
- Delay = MAXDTMFSNDIFFERENCE * 20mS
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 75
52
+ #define MAXDTMFSNDIFFERENCE 6
47
53
 
48
54
 
49
55
  /*
@@ -30,7 +30,7 @@ int32_t endport = 20000;
30
30
 
31
31
  void boost::throw_exception( std::exception const & e ) {
32
32
  std::string err = boost::diagnostic_information( e );
33
- fprintf( stderr, err.c_str() );
33
+ fprintf( stderr, "%s", err.c_str() );
34
34
  exit( EXIT_FAILURE );
35
35
  }
36
36
 
@@ -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, ts, ssrc ) {
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 * 160, 23*20, channel.local.port, server, false, "4" )
128
- senddtmf( 24, 22 * 160, 24*20, channel.local.port, server, false, "4" )
129
- senddtmf( 25, 22 * 160, 25*20, channel.local.port, server, true, "4" )
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
- for( let i = 0; 13 > i; i ++ ) {
436
- sendpk( i, i*20, channel.local.port, server )
437
- }
438
-
439
- senddtmf( 13, 12 * 160, 13*20, channel.local.port, server, false, "4" )
440
- senddtmf( 14, 12 * 160, 14*20, channel.local.port, server, false, "4" )
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( 15, 12 * 160, 15*20, channel.port, server, true, "4" )
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 )
443
468
 
444
- for( let i = 17; i < 17+75; i ++ ) {
445
- sendpk( i, (i-3)*20, channel.local.port, server )
446
- }
447
-
448
- setTimeout( () => channel.close(), 2600 )
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( 83 )
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
- for( let i = 0; 13 > i; i ++ ) {
525
- sendpk( i, i*20, channela.local.port, endpointa )
526
- }
527
-
528
- senddtmf( 13, 12 * 160, 13*20, channela.local.port, endpointa, false, "4" )
529
- senddtmf( 14, 12 * 160, 14*20, channela.local.port, endpointa, false, "4" )
530
- senddtmf( 15, 12 * 160, 15*20, channela.local.port, endpointa, true, "4" )
531
-
532
- for( let i = 16; 23 > i; i ++ ) {
533
- sendpk( i, (i-3)*20, channela.local.port, endpointa )
534
- }
535
-
536
- senddtmf( 23, 22 * 160, 23*20, channela.local.port, endpointa, false, "5" )
537
- senddtmf( 24, 22 * 160, 24*20, channela.local.port, endpointa, false, "5" )
538
- senddtmf( 25, 22 * 160, 25*20, channela.local.port, endpointa, true, "5" )
539
-
540
- for( let i = 26; 50 > i; i ++ ) {
541
- sendpk( i, (i-6)*20, channela.local.port, endpointa )
542
- }
543
-
544
- await new Promise( ( r ) => { setTimeout( () => r(), 1500 ) } )
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.equal( 6 )
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
- expect( receivedmessages[ 0 ] ).to.deep.include( expectedmessages[ 0 ] )
566
- expect( receivedmessages[ 1 ] ).to.deep.include( expectedmessages[ 1 ] )
567
- expect( receivedmessages[ 2 ] ).to.deep.include( expectedmessages[ 2 ] )
568
- expect( receivedmessages[ 3 ] ).to.deep.include( expectedmessages[ 3 ] )
569
- expect( receivedmessages[ 4 ] ).to.deep.include( expectedmessages[ 4 ] )
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
 
@@ -657,19 +711,19 @@ describe( "dtmf", function() {
657
711
 
658
712
  /* send a packet every 20mS x 50 */
659
713
  /* NO FOR LOOPS for explicit readablity of the test */
660
- sendpk( 0, 0, channela.local.port, endpointa )
661
- sendpk( 1, 20, channela.local.port, endpointa )
662
- sendpk( 2, 2*20, channela.local.port, endpointa )
663
- sendpk( 3, 3*20, channela.local.port, endpointa )
664
- sendpk( 4, 4*20, channela.local.port, endpointa )
665
- sendpk( 5, 5*20, channela.local.port, endpointa )
666
- sendpk( 6, 6*20, channela.local.port, endpointa )
667
- sendpk( 7, 7*20, channela.local.port, endpointa )
668
- sendpk( 8, 8*20, channela.local.port, endpointa )
669
- sendpk( 9, 9*20, channela.local.port, endpointa )
670
- sendpk( 10, 10*20, channela.local.port, endpointa )
671
- sendpk( 11, 11*20, channela.local.port, endpointa )
672
- sendpk( 12, 12*20, channela.local.port, endpointa )
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 )
673
727
 
674
728
  /* rfc2833 - 3.6: An audio source SHOULD start transmitting event packets as soon as it
675
729
  recognizes an event and every 50 ms thereafter or the packet interval
@@ -678,48 +732,48 @@ describe( "dtmf", function() {
678
732
  with every packet.
679
733
  senddtmf( sn, ts, sendtime, port, socket, endofevent, event )
680
734
  sendpk( sn, sendtime, port, socket, pt, ts, ssrc ) */
681
- senddtmf( 13, 12 * 160, 13*20, channela.local.port, endpointa, false, "4" )
682
- sendpk( 14, 13*20, channela.local.port, endpointa, 0, 13*160 )
683
- senddtmf( 15, 15 * 160, 15*20, channela.local.port, endpointa, false, "4" )
684
- sendpk( 16, 14*20, channela.local.port, endpointa, 0, 14*160 )
685
- senddtmf( 17, 17 * 160, 17*20, channela.local.port, endpointa, true, "4" )
686
-
687
- sendpk( 18, 15*20, channela.local.port, endpointa, 0, 15*160 )
688
- sendpk( 19, 16*20, channela.local.port, endpointa, 0, 16*160 )
689
- sendpk( 20, 17*20, channela.local.port, endpointa, 0, 17*160 )
690
- sendpk( 21, 18*20, channela.local.port, endpointa, 0, 18*160 )
691
- sendpk( 22, 19*20, channela.local.port, endpointa, 0, 19*160 )
692
-
693
- senddtmf( 23, 20*160, 20*20, channela.local.port, endpointa, false, "5" )
694
- sendpk( 24, 20*20, channela.local.port, endpointa, 0, 20*160 )
695
- senddtmf( 25, 22*160, 21*20, channela.local.port, endpointa, false, "5" )
696
- sendpk( 26, 21*20, channela.local.port, endpointa, 0, 21*160 )
697
- senddtmf( 27, 24*160, 22*20, channela.local.port, endpointa, true, "5" )
698
-
699
- sendpk( 27, 22*20, channela.local.port, endpointa, 0, 22*160 )
700
- sendpk( 28, 23*20, channela.local.port, endpointa, 0, 23*160 )
701
- sendpk( 29, 24*20, channela.local.port, endpointa, 0, 24*160 )
702
- sendpk( 30, 25*20, channela.local.port, endpointa, 0, 25*160 )
703
- sendpk( 31, 26*20, channela.local.port, endpointa, 0, 26*160 )
704
- sendpk( 32, 27*20, channela.local.port, endpointa, 0, 27*160 )
705
- sendpk( 33, 28*20, channela.local.port, endpointa, 0, 28*160 )
706
- sendpk( 34, 29*20, channela.local.port, endpointa, 0, 29*160 )
707
- sendpk( 35, 30*20, channela.local.port, endpointa, 0, 30*160 )
708
- sendpk( 36, 31*20, channela.local.port, endpointa, 0, 31*160 )
709
- sendpk( 37, 32*20, channela.local.port, endpointa, 0, 32*160 )
710
- sendpk( 38, 33*20, channela.local.port, endpointa, 0, 33*160 )
711
- sendpk( 39, 34*20, channela.local.port, endpointa, 0, 34*160 )
712
- sendpk( 40, 35*20, channela.local.port, endpointa, 0, 35*160 )
713
- sendpk( 41, 36*20, channela.local.port, endpointa, 0, 36*160 )
714
- sendpk( 42, 37*20, channela.local.port, endpointa, 0, 37*160 )
715
- sendpk( 43, 38*20, channela.local.port, endpointa, 0, 38*160 )
716
- sendpk( 44, 39*20, channela.local.port, endpointa, 0, 39*160 )
717
- sendpk( 45, 40*20, channela.local.port, endpointa, 0, 40*160 )
718
- sendpk( 46, 41*20, channela.local.port, endpointa, 0, 41*160 )
719
- sendpk( 47, 42*20, channela.local.port, endpointa, 0, 42*160 )
720
- sendpk( 48, 43*20, channela.local.port, endpointa, 0, 43*160 )
721
- sendpk( 49, 44*20, channela.local.port, endpointa, 0, 44*160 )
722
- sendpk( 50, 45*20, channela.local.port, endpointa, 0, 45*160 )
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 )
723
777
 
724
778
  await new Promise( ( resolve ) => { setTimeout( () => resolve(), 1200 ) } )
725
779
 
@@ -736,8 +790,8 @@ describe( "dtmf", function() {
736
790
 
737
791
  // 3 after we return to the event loop and enter the callback with close event.
738
792
  expect( dtmfapkcount ).to.equal( 0 )
739
- expect( dtmfbpkcount ).to.equal( 6 )
740
- expect( dtmfcpkcount ).to.equal( 6 )
793
+ expect( dtmfbpkcount ).to.be.within( 4, 8 )
794
+ expect( dtmfcpkcount ).to.be.within( 4, 8 )
741
795
 
742
796
  expect( receveiedmessages[ 0 ].action ).to.equal( "mix" )
743
797
  expect( receveiedmessages[ 1 ].action ).to.equal( "mix" )
@@ -792,29 +846,29 @@ describe( "dtmf", function() {
792
846
 
793
847
  // Event "3"
794
848
  const dstport = channel.local.port
795
- sendpk( 948, 0, dstport, server, 0, 148480, 518218235 )
849
+ sendpk( 948, 148480, 0, dstport, server, 0, 518218235 )
796
850
  sendpayload( 20, fromstr( "80 e5 03 b5 00 02 44 a0 1e e3 61 fb 03 0a 00 a0 4c d1" ), dstport, server )
797
- sendpk( 950, 40, dstport, server, 0, 148800, 518218235 )
851
+ sendpk( 950, 148800, 40, dstport, server, 0, 518218235 )
798
852
  sendpayload( 60, fromstr( "80 65 03 b7 00 02 44 a0 1e e3 61 fb 03 0a 01 40 25 b8" ), dstport, server )
799
- sendpk( 952, 80, dstport, server, 0, 149120, 518218235 )
853
+ sendpk( 952, 149120, 80, dstport, server, 0, 518218235 )
800
854
  sendpayload( 100, fromstr( "80 65 03 b9 00 02 44 a0 1e e3 61 fb 03 0a 01 e0 e8 81" ), dstport, server )
801
- sendpk( 954, 120, dstport, server, 0, 149440, 518218235 )
855
+ sendpk( 954, 149440,120, dstport, server, 0, 518218235 )
802
856
  sendpayload( 140, fromstr( "80 65 03 bb 00 02 44 a0 1e e3 61 fb 03 0a 02 80 e2 74" ), dstport, server )
803
- sendpk( 956, 160, dstport, server, 0, 149760, 518218235 )
857
+ sendpk( 956, 149760, 160, dstport, server, 0, 518218235 )
804
858
  sendpayload( 180, fromstr( "80 65 03 bd 00 02 44 a0 1e e3 61 fb 03 0a 03 20 1f bb" ), dstport, server )
805
- sendpk( 958, 200, dstport, server, 0, 150080, 518218235 )
859
+ sendpk( 958, 150080, 200, dstport, server, 0, 518218235 )
806
860
  sendpayload( 220, fromstr( "80 65 03 bf 00 02 44 a0 1e e3 61 fb 03 0a 03 c0 13 0c" ), dstport, server )
807
- sendpk( 960, 240, dstport, server, 0, 150400, 518218235 )
861
+ sendpk( 960, 150400,240, dstport, server, 0, 518218235 )
808
862
  sendpayload( 260, fromstr( "80 65 03 c1 00 02 44 a0 1e e3 61 fb 03 0a 04 60 2e bf" ), dstport, server )
809
- sendpk( 962, 280, dstport, server, 0, 150720, 518218235 )
863
+ sendpk( 962, 150720, 280, dstport, server, 0, 518218235 )
810
864
  sendpayload( 300, fromstr( "80 65 03 c3 00 02 44 a0 1e e3 61 fb 03 8a 04 60 05 c1" ), dstport, server )
811
865
  sendpayload( 320 ,fromstr( "80 65 03 c4 00 02 44 a0 1e e3 61 fb 03 8a 04 60 bb 69" ), dstport, server )
812
- sendpk( 965, 340, dstport, server, 0, 151200, 518218235 )
866
+ sendpk( 965, 151200, 340, dstport, server, 0, 518218235 )
813
867
  sendpayload( 360, fromstr( "80 65 03 c6 00 02 44 a0 1e e3 61 fb 03 8a 04 60 1e 27" ), dstport, server )
814
- sendpk( 967, 380, dstport, server, 0, 151520, 518218235 )
815
- sendpk( 968, 400, dstport, server, 0, 151680, 518218235 )
816
- sendpk( 969, 420, dstport, server, 0, 151840, 518218235 )
817
- sendpk( 970, 440, dstport, server, 0, 152000, 518218235 )
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 )
818
872
 
819
873
  setTimeout( () => channel.close(), 25*20 )
820
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 finished
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( 3000, 7000 ) /* 200mS of audio */
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( 3000, 7000 )
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( 3000, 7000 )
248
+ expect( stats.size ).to.be.within( 2500, 7000 )
257
249
 
258
250
  } )
259
251