我正在尝试通过 WebRTC 共享文件,但一段时间后它会停止,并且记录 RTCDatachannel 发送队列已满
let file = fileUpload.files[0];
let offset = 0;
let chunkSize = 1024*1024*16;
file.arrayBuffer().then((buffer) => {
while(buffer.byteLength){
const chunk = buffer.slice(0, chunkSize);
buffer = buffer.slice(chunkSize, buffer.byteLength);
dataChannel.send(chunk);
}
})
它适用于小文件,但适用于大文件。
let file = fileUpload.files[0];
let offset = 0;
let chunkSize = 1024*1024*16;
file.arrayBuffer().then((buffer) => {
while(buffer.byteLength){
const chunk = buffer.slice(0, chunkSize);
buffer = buffer.slice(chunkSize, buffer.byteLength);
dataChannel.send(chunk);
}
})
it works fine for small files but stops with big size files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataChannel
有一个bufferedAmount
属性,它告诉您还有多少字节等待发送。它还有一个名为bufferedAmountLowThreshold
的属性。https://developer.mozilla.org/en-US/docs /Web/API/RTCDataChannel/bufferedAmountLowThreshold
https://developer.mozilla.org/en-US/docs /Web/API/RTCDataChannel/bufferedAmount
只要
bufferedAmount
以下,您就可以继续正常发送数据bufferedAmountLowThreshold
。一旦它变大,您就停止排队更多数据,直到收到bufferedamountlow
事件。A
DataChannel
has abufferedAmount
property which tells you how many bytes are still waiting to be sent. It also has a property calledbufferedAmountLowThreshold
.https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/bufferedAmountLowThreshold
https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/bufferedAmount
You could keep sending data as normal as long as
bufferedAmount
is belowbufferedAmountLowThreshold
. Once it is larger you stop queuing more data until you receive abufferedamountlow
event.