@babblevoice/projectrtp 2.4.17 → 2.5.22

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.
@@ -1,9 +1,9 @@
1
1
 
2
2
  const expect = require( "chai" ).expect
3
- const projectrtp = require( "../../index.js" ).projectrtp
3
+ const projectrtp = require( "../../index" ).projectrtp
4
4
  const dgram = require( "dgram" )
5
5
 
6
- const pcap = require( "./pcap.js" )
6
+ const pcap = require( "./pcap" )
7
7
 
8
8
  /*
9
9
  i.e. the RTP payload
@@ -23,6 +23,21 @@ function sendpayload( sendtime, pk, dstport, server ) {
23
23
  }, sendtime )
24
24
  }
25
25
 
26
+ /**
27
+ * Limitation of not parsing ccrc.
28
+ * @param { Buffer } packet
29
+ * @return { object }
30
+ */
31
+ function parsepk( packet ) {
32
+ return {
33
+ sn: packet.readUInt16BE( 2 ),
34
+ ts: packet.readUInt32BE( 4 ),
35
+ pt: packet.readUInt8( 1 ) & 0x7f,
36
+ ssrc: packet.readUInt32BE( 8 ),
37
+ payload: new Uint8Array( packet.slice( 12 ) )
38
+ }
39
+ }
40
+
26
41
  /* helper functions */
27
42
  function sendpk( sn, ts, sendtime, dstport, server, pt = 0, ssrc ) {
28
43
 
@@ -253,6 +268,74 @@ describe( "dtmf", function() {
253
268
  expect( dtmfpkcount ).to.equal( 3*3 )
254
269
  } )
255
270
 
271
+ it( "2 channels mixing and request rtp server to send 2833 to one with dynamic payloadtype", async function() {
272
+
273
+ /* create our RTP/UDP endpoint */
274
+ const clienta = dgram.createSocket( "udp4" )
275
+ const clientb = dgram.createSocket( "udp4" )
276
+
277
+ const rfc2833pt = 44
278
+
279
+ let dtmfpkcount = 0
280
+ clienta.on( "message", function( msg ) {
281
+ if( rfc2833pt == ( 0x7f & msg [ 1 ] ) ) {
282
+ dtmfpkcount++
283
+ } else {
284
+ expect( msg.length ).to.equal( 172 )
285
+ expect( 0x7f & msg [ 1 ] ).to.equal( 0 )
286
+ }
287
+ } )
288
+
289
+ clientb.on( "message", function( msg ) {
290
+ if( 101 == ( 0x7f & msg [ 1 ] ) ) {
291
+ expect( true ).to.equal( false ) //here = bad
292
+ dtmfpkcount++
293
+ }
294
+ clientb.send( msg, channelb.local.port, "localhost" )
295
+ } )
296
+
297
+ this.timeout( 3000 )
298
+ this.slow( 2500 )
299
+
300
+ clienta.bind()
301
+ await new Promise( ( resolve ) => { clienta.on( "listening", () => resolve() ) } )
302
+ clientb.bind()
303
+ await new Promise( ( resolve ) => { clientb.on( "listening", () => resolve() ) } )
304
+
305
+ const ouraport = clienta.address().port
306
+ const ourbport = clientb.address().port
307
+
308
+ let done
309
+ const finished = new Promise( ( r ) => { done = r } )
310
+
311
+ const channela = await projectrtp.openchannel( { "remote": { "address": "localhost", "port": ouraport, "codec": 0, rfc2833pt } }, function( d ) {
312
+ if( "close" === d.action ) channelb.close()
313
+ } )
314
+
315
+ const channelb = await projectrtp.openchannel( { "remote": { "address": "localhost", "port": ourbport, "codec": 0 } }, function( d ) {
316
+ if( "close" === d.action ) done()
317
+ } )
318
+
319
+ expect( channela.mix( channelb ) ).to.be.true
320
+
321
+ /* send a packet every 20mS x 70 */
322
+ for( let i = 0; 50 > i; i ++ ) {
323
+ sendpk( i, i*160, i*20, channela.local.port, clienta )
324
+ }
325
+
326
+ await new Promise( ( resolve ) => { setTimeout( () => resolve(), 400 ) } )
327
+ channela.dtmf( "*9F" )
328
+ await new Promise( ( resolve ) => { setTimeout( () => resolve(), 800 ) } )
329
+ channela.close()
330
+
331
+ await finished
332
+
333
+ clienta.close()
334
+ clientb.close()
335
+
336
+ expect( dtmfpkcount ).to.equal( 3*3 )
337
+ } )
338
+
256
339
  it( "3 channels mixing and request rtp server to send 2833 to one", async function() {
257
340
 
258
341
  /* create our RTP/UDP endpoint */
@@ -262,11 +345,12 @@ describe( "dtmf", function() {
262
345
 
263
346
  let dtmfpkcount = 0
264
347
  clienta.on( "message", function( msg ) {
265
- if( 101 == ( 0x7f & msg [ 1 ] ) ) {
348
+ const pk = parsepk( msg )
349
+ if( 101 == pk.pt ) {
266
350
  dtmfpkcount++
267
351
  } else {
268
352
  expect( msg.length ).to.equal( 172 )
269
- expect( 0x7f & msg [ 1 ] ).to.equal( 0 )
353
+ expect( pk.pt ).to.equal( 0 )
270
354
  }
271
355
  } )
272
356
 
@@ -904,8 +904,7 @@ describe( "channel mix", function() {
904
904
  expect( endpointbpkcountzero ).to.be.within( 65, 75 )
905
905
  expect( endpointcpkcountzero ).to.be.within( 65, 75 )
906
906
  expect( endpointapkcountnotzero ).to.be.within( 4, 12 )
907
- expect( endpointbpkcountnotzero ).to.be.within( 4
908
- , 12 )
907
+ expect( endpointbpkcountnotzero ).to.be.within( 4, 12 )
909
908
  expect( endpointcpkcountnotzero ).to.be.below( 2 )
910
909
 
911
910
  await finished