diff --git a/doc/demo/client/index.html b/doc/demo/client/index.html
index 3af412b..784e9da 100644
--- a/doc/demo/client/index.html
+++ b/doc/demo/client/index.html
@@ -30,6 +30,7 @@
+
class ConvertHelper {
constructor() {
this.buf = null;
@@ -78,34 +79,24 @@
} else {
this.isChunk = false;
}
-
+ // console.log(`buf.byteLength: ${buf.byteLength}`);
+ // console.log(buf);
if (this.isChunk) {
if (!this.isStartValid(buf)) {
- buf = this.concat(this.buf, buf);
- this.buf = null;
+ // buf = this.concat(this.buf, buf);
+ buf = this.getBufAll(buf);
}
// console.log(buf);
// console.log(this.isStartValid(buf));
// console.log(this.isEndValid(buf));
// console.log(this.getLastInValidPos(buf));
-
if (!this.isEndValid(buf)) {
- var pos = this.getLastInValidPos(buf);
- if (pos < 0) {
- cb(null, this.forceUtf8Slice(buf.subarray(0, pos)));
- this.buf = buf.subarray(pos);
- } else {
- cb(null, this.forceUtf8Slice(buf));
- this.buf = null;
- }
+ this.bufList.push(buf);
} else {
- cb(null, this.forceUtf8Slice(buf));
- this.buf = null;
+ cb(null, this.forceUtf8Slice(this.getBufAll(buf)));
}
} else {
- buf = this.concat(this.buf, buf);
- this.buf = null;
- cb(null, this.forceUtf8Slice(buf));
+ cb(null, this.forceUtf8Slice(this.getBufAll(buf)));
}
}
@@ -135,21 +126,10 @@
if (buf instanceof ArrayBuffer) {
buf = new Uint8Array(buf);
}
- if (buf.byteLength >= 4 * 1024) {
- this.isChunk = true;
- } else {
- this.isChunk = false;
- }
-
- if (!this.isChunk) {
+ if (this.isEndValid(buf)) {
cb(null, this.forceUtf8Slice(this.getBufAll(buf)));
- this.bufList.length = 0;
} else {
- if (this.isEndValid(buf)) {
- cb(null, this.forceUtf8Slice(this.getBufAll(buf)));
- } else {
- this.bufList.push(buf);
- }
+ this.bufList.push(buf);
}
}
diff --git a/pkg/api/controller.go b/pkg/api/controller.go
index f2186b9..2f2d1cf 100644
--- a/pkg/api/controller.go
+++ b/pkg/api/controller.go
@@ -85,7 +85,7 @@ func (handler *streamHandler) Read(p []byte) (size int, err error) {
// executor 回调想web 输出
func (handler *streamHandler) Write(p []byte) (size int, err error) {
size = len(p)
- copy := append(make([]byte, 0, size), p...)
+ copy := append(make([]byte, 0, size), p...) // 解决 发送数据丢失的问题
err = handler.wsConn.WsWrite(websocket.BinaryMessage, copy)
return
}