From 4d8a619d51acfbe27357db05d17514773a5a1142 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 18 Jul 2024 17:43:55 +0200 Subject: [PATCH 1/2] fix: increase WebRTC max datachannel message size The 16KB limit was fixed in browsers quite a while back so we should be able to increase the max datachannel message size to 256KB at least. Fixes #2612 --- packages/transport-webrtc/src/stream.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/transport-webrtc/src/stream.ts b/packages/transport-webrtc/src/stream.ts index d875b2be40..b95c485549 100644 --- a/packages/transport-webrtc/src/stream.ts +++ b/packages/transport-webrtc/src/stream.ts @@ -46,8 +46,11 @@ export const VARINT_LENGTH = 2 /** * Max message size that can be sent to the DataChannel + * + * @see https://blog.mozilla.org/webrtc/large-data-channel-messages/ + * @see https://issues.webrtc.org/issues/40644524 */ -export const MAX_MESSAGE_SIZE = 16 * 1024 +export const MAX_MESSAGE_SIZE = 256 * 1024 /** * When closing streams we send a FIN then wait for the remote to From 161b2f5bf27a85710c4709499560f5876bfa54af Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 19 Jul 2024 11:48:17 +0200 Subject: [PATCH 2/2] chore: increase protobuf overhead as more bytes are needed to length encode 256k --- packages/transport-webrtc/src/stream.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/transport-webrtc/src/stream.ts b/packages/transport-webrtc/src/stream.ts index b95c485549..b21b29b944 100644 --- a/packages/transport-webrtc/src/stream.ts +++ b/packages/transport-webrtc/src/stream.ts @@ -35,9 +35,9 @@ export const MAX_BUFFERED_AMOUNT = 16 * 1024 * 1024 export const BUFFERED_AMOUNT_LOW_TIMEOUT = 30 * 1000 /** - * protobuf field definition overhead + * protobuf field definition overhead + length encoding prefix length */ -export const PROTOBUF_OVERHEAD = 5 +export const PROTOBUF_OVERHEAD = 7 /** * Length of varint, in bytes