WebRTC数据通道缓冲区已满
首先,我希望你明白我的英语不好 对于文件传输,在网格拓扑中,在Chrome中 当缓冲量为16MB时,通道关闭并显示错误消息 “未捕获的网络错误:未能在“RTCDataChannel”上执行“发送”:无法发送数据“WebRTC数据通道缓冲区已满,webrtc,file-transfer,rtcdatachannel,peer-connection,Webrtc,File Transfer,Rtcdatachannel,Peer Connection,首先,我希望你明白我的英语不好 对于文件传输,在网格拓扑中,在Chrome中 当缓冲量为16MB时,通道关闭并显示错误消息 “未捕获的网络错误:未能在“RTCDataChannel”上执行“发送”:无法发送数据“ (它使用的是chrome,而不是firefox。) 如何发送文件(超过16MB) fileWorker.js 我试图解决这个问题。 我只是使用带有setTimeout的递归函数调用 代码 \u fileToPeers:function(块、文件名、progressCallbackId)
(它使用的是chrome,而不是firefox。) 如何发送文件(超过16MB) fileWorker.js
我试图解决这个问题。
我只是使用带有setTimeout的递归函数调用 代码
\u fileToPeers:function(块、文件名、progressCallbackId){
var callback=callbacks[progressCallbackId];
objForEach(this.peer,function(peer){
var channel=peer.fileChannel;
if(通道&&!通道使用){
channel.using=true;
此._chunksInChannel(chunks,0,文件名,通道,回调);
}
},这个);
删除回调[progressCallbackId];
},
_chunksInChannel:函数(chunks、chunkIdx、文件名、通道、回调){
var length=chunks.length,
doNext=chunkIdxchannel_BUFFER_MAX){
setTimeout(函数(){
这是._chunksInChannel(chunks,chunkIdx,fileName,channel,callback);
}.绑定(本),500);
doNext=false;
}否则{
send(chunks[chunkIdx]);
chunkIdx+=1;
if(chunkIdx==长度){
send(['end',fileName].join(',');
doNext=false;
channel.using=false;
}
回调(chunkIdx);
}
}
},
难道你没有更好的吗?只要等待缓冲区未满,就可以成功发送数据。
var chunkSize = 16384;
onmessage = function(event) {
var file = event.data[0],
callbackId = event.data[1],
totalSize = file.size,
chunks = [],
curSize = 0,
reader,
chunk;
if (!FileReaderSync) {
reader = new FileReader();
reader.onload = function(event) {
console.log('chunking...');
chunks.push(event.target.result);
curSize += chunkSize;
slice();
};
slice();
} else {
reader = new FileReaderSync();
while (curSize < totalSize) {
console.log('chunking...');
chunk = file.slice(curSize, curSize + chunkSize);
chunks.push(reader.readAsArrayBuffer(chunk));
curSize += chunkSize;
}
postMessage([chunks, file.name, callbackId]);
}
function slice() {
if (curSize > totalSize) {
postMessage([chunks, file.name, callbackId]);
} else {
chunk = file.slice(curSize, curSize + chunkSize);
reader.readAsArrayBuffer(chunk);
}
}
};
_fileToPeers: function(chunks, fileName, progressCallbackId) {
var callback = callbacks[progressCallbackId],
chunkCount,
peerCount = 0;
objForEach(this.peers, function(peer) {
var channel = peer.fileChannel;
peerCount += 1;
if (channel) {
chunkCount = 0;
chunks.forEach(function(chunk) {
channel.send(chunk);
chunkCount += 1;
console.log('sending...'); // abnormal works!
callback(peerCount, chunkCount); // abnormal works!
});
channel.send(['end', fileName].join(','));
}
});
delete callbacks[progressCallbackId];
},
_fileToPeers: function(chunks, fileName, progressCallbackId) {
var callback = callbacks[progressCallbackId];
objForEach(this.peers, function(peer) {
var channel = peer.fileChannel;
if (channel && !channel.using) {
channel.using = true;
this._chunksInChannel(chunks, 0, fileName, channel, callback);
}
}, this);
delete callbacks[progressCallbackId];
},
_chunksInChannel: function(chunks, chunkIdx, fileName, channel, callback) {
var length = chunks.length,
doNext = chunkIdx < length;
while (doNext) {
if (channel.bufferedAmount > CHANNEL_BUFFER_MAX) {
setTimeout(function () {
this._chunksInChannel(chunks, chunkIdx, fileName, channel, callback);
}.bind(this), 500);
doNext = false;
} else {
channel.send(chunks[chunkIdx]);
chunkIdx += 1;
if (chunkIdx === length) {
channel.send(['end', fileName].join(','));
doNext = false;
channel.using = false;
}
callback(chunkIdx);
}
}
},