Commit 33bc366c authored by xuchaozou's avatar xuchaozou

feat: 优化加载页速度

parent 360a03af
Pipeline #86021 passed with stages
......@@ -146,7 +146,6 @@ class PandaRecordWebSocket extends PandaWebSocket {
if([this.ws.CONNECTING, this.ws.OPEN].includes(this.ws.readyState)) {
this.frameBuffers.push(frameBuffer)
} else if(this.ws.CLOSED == this.ws.readyState){
this.frameBuffers.push(frameBuffer)
this.ws = null
}
}
......@@ -183,18 +182,18 @@ class PandaRecordWebSocket extends PandaWebSocket {
this.time = setInterval(function () {
if (!this.ws) return
if (this.ws.readyState != this.ws.OPEN) return
const frameBuffer = this.frameBuffers.shift()
if (!frameBuffer) return
if(this.frameBuffers.length == 0) return
this.ws.send(
JSON.stringify({
data: {
format,
encoding,
status: 1,
audio: Utils.toBase64(frameBuffer),
audio: Utils.toBase64(Utils.mergeArrayBuffers(this.frameBuffers)),
},
})
)
this.frameBuffers = []
}.bind(this), 40)
}
......
......@@ -15,6 +15,18 @@ const Utils = {
}, time);
});
},
mergeArrayBuffers(buffers) {
if(buffers.length == 1) return buffers[0]
const byteLength = buffers.reduce((prev , cur) => prev + cur.byteLength , 0)
const mergeBuffer = new ArrayBuffer(byteLength)
const mergeView = new Uint8Array(mergeBuffer)
let offset = 0
for(let i = 0 ; i < buffers.length ; i++) {
mergeView.set(new Uint8Array(buffers[i]), offset)
offset += buffers[i].byteLength
}
return mergeBuffer
},
getMediaCodeToMsg(code) {
if (/device not found/.test(code)) {
return '没有发现录音设备';
......
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