Skip to content

Commit 9e92b0c

Browse files
authored
fix: increase WebRTC max datachannel message size (#2627)
We automatically chunk stream messages larger than [16KB](https://github.com/libp2p/js-libp2p/blob/main/packages/transport-webrtc/src/stream.ts#L50) when sending over a datachannel. This limit is based on [browser limitations](https://lgrahl.de/articles/demystifying-webrtc-dc-size-limit.html) that have since been resolved. We should be ok to increase the limit to [256KB at least](https://issues.webrtc.org/issues/40644524), maybe more. Ref: https://blog.mozilla.org/webrtc/large-data-channel-messages/ Fixes #2612
1 parent 4a994c5 commit 9e92b0c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/transport-webrtc/src/stream.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export const MAX_BUFFERED_AMOUNT = 2 * 1024 * 1024
3535
export const BUFFERED_AMOUNT_LOW_TIMEOUT = 30 * 1000
3636

3737
/**
38-
* protobuf field definition overhead
38+
* protobuf field definition overhead + length encoding prefix length
3939
*/
40-
export const PROTOBUF_OVERHEAD = 5
40+
export const PROTOBUF_OVERHEAD = 7
4141

4242
/**
4343
* Length of varint, in bytes
@@ -46,8 +46,11 @@ export const VARINT_LENGTH = 2
4646

4747
/**
4848
* Max message size that can be sent to the DataChannel
49+
*
50+
* @see https://blog.mozilla.org/webrtc/large-data-channel-messages/
51+
* @see https://issues.webrtc.org/issues/40644524
4952
*/
50-
export const MAX_MESSAGE_SIZE = 16 * 1024
53+
export const MAX_MESSAGE_SIZE = 256 * 1024
5154

5255
/**
5356
* When closing streams we send a FIN then wait for the remote to

0 commit comments

Comments
 (0)