ws.socket.onmessage = res => {//ws訂閱後接收數據
var blob = res.data//接收blob對象
var reader = new FileReader()
reader.readAsArrayBuffer(blob)//講blob對象數據轉化成ArrayBuffer類數組
reader.onload = function(e){
if(e.target.readyState == FileReader.DONE){
let data = pako.inflate(reader.result)//使用pako.js將ArrayBuffer類數組轉化成Uint8Array
strData = String.fromCharCode.apply(null, new Uint16Array(data))//轉化成JSON字符串
console.log(JSON.parse(strData))
}
}
}