mirror of
https://github.com/MercuryWorkshop/adrift.git
synced 2025-05-13 14:20:01 -04:00
reduce max resp chunk size well below webrtc max
This commit is contained in:
parent
52a55f616b
commit
fa3386468e
2 changed files with 11 additions and 1 deletions
|
@ -49,4 +49,7 @@ export type WSErrorPayload = {
|
||||||
message: string;
|
message: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// WebRTC max is 16K, let's say 8K to be safe
|
||||||
|
export const MAX_CHUNK_SIZE = 8 * 1024;
|
||||||
|
|
||||||
export { Transport } from "./Transport";
|
export { Transport } from "./Transport";
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {
|
||||||
C2SRequestTypes,
|
C2SRequestTypes,
|
||||||
HTTPRequestPayload,
|
HTTPRequestPayload,
|
||||||
HTTPResponsePayload,
|
HTTPResponsePayload,
|
||||||
|
MAX_CHUNK_SIZE,
|
||||||
ProtoBareHeaders,
|
ProtoBareHeaders,
|
||||||
S2CRequestType,
|
S2CRequestType,
|
||||||
S2CRequestTypes,
|
S2CRequestTypes,
|
||||||
|
@ -235,7 +236,13 @@ export class AdriftServer {
|
||||||
const { payload, body } = resp;
|
const { payload, body } = resp;
|
||||||
this.sendHTTPResponseStart(seq, payload);
|
this.sendHTTPResponseStart(seq, payload);
|
||||||
for await (const chunk of body) {
|
for await (const chunk of body) {
|
||||||
this.sendHTTPResponseChunk(seq, new Uint8Array(chunk));
|
let chunkPart = null;
|
||||||
|
let chunkRest = chunk;
|
||||||
|
do {
|
||||||
|
chunkPart = chunkRest.slice(0, MAX_CHUNK_SIZE);
|
||||||
|
chunkRest = chunkRest.slice(MAX_CHUNK_SIZE);
|
||||||
|
this.sendHTTPResponseChunk(seq, new Uint8Array(chunkPart));
|
||||||
|
} while (chunkRest.byteLength > 0);
|
||||||
}
|
}
|
||||||
this.sendHTTPResponseEnd(seq);
|
this.sendHTTPResponseEnd(seq);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue