概述WebTransport 提供基于 QUIC 的低延迟传输。本文给出最小能力检测与发送示例。能力检测与发送const supportsWT = typeof WebTransport === 'function'; async function sendChunks(url, file, size = 1024 * 512) { if (!supportsWT) throw new Error('unsupported'); const wt = new WebTransport(url); await wt.ready; const stream = await wt.createBidirectionalStream(); const writer = stream.writable.getWriter(); let o = 0, i = 0; while (o < file.size) { const b = file.slice(o, o + size); const ab = await b.arrayBuffer(); await writer.write(new Uint8Array(ab)); o += size; i++; } await writer.close(); }

发表评论 取消回复