Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bridges/punchd-bridge/gateway/public/js/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ async function handleViaDataChannel(clientId, request) {
}, 10000);

mc.port1.onmessage = function (e) {
// Progress signal: large response started downloading, extend timeout
if (e.data && e.data.type === "progress") {
clearTimeout(timer);
timer = setTimeout(function () {
resolve(fetch(fallbackRequest));
}, 300000); // 5 minutes for large downloads (video segments)
return;
}
clearTimeout(timer);
if (e.data.error) {
resolve(fetch(fallbackRequest));
Expand Down
18 changes: 17 additions & 1 deletion bridges/punchd-bridge/gateway/public/js/webrtc-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,20 @@
streaming: true,
});
}
} else {
// Buffered streaming (video, large files) — extend timeouts since
// the full response must be received before we can deliver it.
// A 50MB 4K segment over DataChannel can take minutes.
var pending = pendingRequests.get(msg.id);
if (pending) {
clearTimeout(pending.timeout);
pending.timeout = setTimeout(function () {
pendingRequests.delete(msg.id);
pending.port.postMessage({ error: "Timeout" });
}, 300000); // 5 minutes for large downloads
// Tell SW to extend its timeout too
pending.port.postMessage({ type: "progress" });
}
}
// live=true: forward chunks to SW via ReadableStream
// live=false: buffer chunks page-side, deliver complete Response on end
Expand Down Expand Up @@ -641,13 +655,15 @@
})
);

const timeout = setTimeout(() => {
var timeout = setTimeout(() => {
pendingRequests.delete(requestId);
streamingPorts.delete(requestId);
responsePort.postMessage({ error: "Timeout" });
}, 15000);

pendingRequests.set(requestId, {
timeout: timeout,
port: responsePort,
resolve: (msg) => {
clearTimeout(timeout);
if (msg.streaming) {
Expand Down
6 changes: 3 additions & 3 deletions bridges/punchd-bridge/gateway/src/webrtc/peer-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export function createPeerHandler(options: PeerHandlerOptions): PeerHandler {

// Queue-based sending with flow control.
// All messages sent as binary to avoid SCTP PPID confusion.
const DC_MAX_BUFFER = 65_536;
const DC_MAX_BUFFER = 512_000; // 512KB — higher buffer for video throughput
const queue: { binary: Buffer }[] = [];
let scheduled = false;

Expand All @@ -300,15 +300,15 @@ export function createPeerHandler(options: PeerHandlerOptions): PeerHandler {
if (dc.bufferedAmount() > DC_MAX_BUFFER) {
res.pause();
scheduled = true;
setTimeout(flush, 5);
setTimeout(flush, 1);
return;
}
try {
const sent = dc.sendMessageBinary(queue[0].binary);
if (!sent) {
res.pause();
scheduled = true;
setTimeout(flush, 10);
setTimeout(flush, 2);
return;
}
} catch {
Expand Down