@@ -6,24 +6,22 @@ import * as lengthPrefixed from 'it-length-prefixed'
66import { pushable } from 'it-pushable'
77import { Uint8ArrayList } from 'uint8arraylist'
88import { Message } from '../src/pb/message.js'
9- import { createStream } from '../src/stream.js'
9+ import { MAX_BUFFERED_AMOUNT , MAX_MESSAGE_SIZE , PROTOBUF_OVERHEAD , createStream } from '../src/stream.js'
1010
1111const mockDataChannel = ( opts : { send : ( bytes : Uint8Array ) => void , bufferedAmount ?: number } ) : RTCDataChannel => {
1212 return {
1313 readyState : 'open' ,
14- close : ( ) => { } ,
15- addEventListener : ( _type : string , _listener : ( ) => void ) => { } ,
16- removeEventListener : ( _type : string , _listener : ( ) => void ) => { } ,
14+ close : ( ) => { } ,
15+ addEventListener : ( _type : string , _listener : ( ) => void ) => { } ,
16+ removeEventListener : ( _type : string , _listener : ( ) => void ) => { } ,
1717 ...opts
1818 } as RTCDataChannel
1919}
2020
21- const MAX_MESSAGE_SIZE = 16 * 1024
22-
2321describe ( 'Max message size' , ( ) => {
2422 it ( `sends messages smaller or equal to ${ MAX_MESSAGE_SIZE } bytes in one` , async ( ) => {
2523 const sent : Uint8ArrayList = new Uint8ArrayList ( )
26- const data = new Uint8Array ( MAX_MESSAGE_SIZE - 5 )
24+ const data = new Uint8Array ( MAX_MESSAGE_SIZE - PROTOBUF_OVERHEAD )
2725 const p = pushable ( )
2826
2927 // Make sure that the data that ought to be sent will result in a message with exactly MAX_MESSAGE_SIZE
@@ -42,8 +40,7 @@ describe('Max message size', () => {
4240 p . end ( )
4341 await webrtcStream . sink ( p )
4442
45- // length(message) + message + length(FIN) + FIN
46- expect ( length ( sent ) ) . to . equal ( 4 )
43+ expect ( length ( sent ) ) . to . equal ( 6 )
4744
4845 for ( const buf of sent ) {
4946 expect ( buf . byteLength ) . to . be . lessThanOrEqual ( MAX_MESSAGE_SIZE )
@@ -80,7 +77,6 @@ describe('Max message size', () => {
8077 } )
8178
8279 it ( 'closes the stream if bufferamountlow timeout' , async ( ) => {
83- const MAX_BUFFERED_AMOUNT = 16 * 1024 * 1024 + 1
8480 const timeout = 100
8581 let closed = false
8682 const webrtcStream = createStream ( {
@@ -91,7 +87,7 @@ describe('Max message size', () => {
9187 send : ( ) => {
9288 throw new Error ( 'Expected to not send' )
9389 } ,
94- bufferedAmount : MAX_BUFFERED_AMOUNT
90+ bufferedAmount : MAX_BUFFERED_AMOUNT + 1
9591 } ) ,
9692 direction : 'outbound' ,
9793 onEnd : ( ) => {
0 commit comments