Commit 36982b4e authored by Skye Yu's avatar Skye Yu

test: continue decode

parent 996e96b0
......@@ -31,7 +31,7 @@ declare class JensenType {
fileName: string,
length: number,
on?: (msg: Uint8Array | 'fail') => void,
onprogress?: (size: number) => void
onprogress?: (size: number, msg: Uint8Array | null) => void
) => void;
getFileBlock: (
fileName: string,
......
......@@ -314,19 +314,15 @@ function Jensen(log) {
// 做一个回调,怎么样找到它呢?
blocks.push(result.data);
tryReceive();
if (self.decodeTimeout) clearTimeout(self.decodeTimeout);
self.decodeTimeout = setTimeout(function () {
tryDecode();
}, self.timewait);
if (self.onreceive) {
const arr = [];
arr.push(result.data);
tryDecode(arr);
try {
self.onreceive(totalBytes);
self.onreceive(totalBytes, continueDecode(result.data));
} catch (e) {
}
} else {
if (self.decodeTimeout) clearTimeout(self.decodeTimeout);
self.decodeTimeout = setTimeout(function () {
tryDecode(blocks);
}, self.timewait);
}
};
......@@ -343,11 +339,12 @@ function Jensen(log) {
} catch (err) {
console.error('ci decode', err);
}
sendNext();
const msg = result.message;
return result && msg.id === TRANSFER_FILE ? msg.body : null;
}
const tryDecode = function (blocks) {
const tryDecode = function () {
// 一个容器,比单独任意一个小包要大一点儿,好像还差一点儿
let stime = new Date();
let buff = new ArrayBuffer(RECV_BUFF_SIZE * 2);
......@@ -790,7 +787,7 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress)
}
};
this.onreceive = onprogress;
Jensen.registerHandler(TRANSFER_FILE, handler);
// Jensen.registerHandler(TRANSFER_FILE, handler);
this.send(new Command(TRANSFER_FILE).body(fname));
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment