概述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(); }

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部