Hello, I am currently facing an issue while trying to retrieve data from a WebSocket using JS and VUE. Here's the problem I'm encountering:
In order to receive data, I am utilizing the following code snippet:
created() {
console.log('Starting Connection to WebSocket')
this.connection = new WebSocket('ws://127.0.0.1:8080/live')
// this.connection = new WebSocket('ws://echo.websocket.org')
this.onopen = function (event) {
console.log(event)
console.log('Success')
}
this.onmessage = webSocketOnMSG
},
Furthermore, I am attempting to parse a blob of data:
function webSocketOnMSG(msg) {
if (typeof (msg.data) === 'string') {
jsonMSG(msg.data)
return
}
bytes = new Uint8Array(msg.data)
console.log('!!!BYTE', bytes)
type = bytes[0]
switch (type) {
}
}
When console.log('!!!BYTE', bytes)
is executed, it displays:
Blob {size: 187086, type: ""}
however, it should actually display:
ArrayBuffer(187086)
As a result, the value of type
is undefined.
This issue does not occur in another version of JavaScript without VUE, where everything works as expected.
I would greatly appreciate any assistance in identifying what might be causing this problem. Thank you!