I've currently initialized two different websockets with different ports like this:
const socket_ch1 = new WebSocket(WEB_socket_URL_CH1)
const socket_ch2 = new WebSocket(WEB_socket_URL_CH2)
socket_ch1.onopen = (event) => {
console.warn('websocket_ch1 connection established', event)
}
socket_ch2.onopen = (event) => {
console.warn('websocket_ch2 connection established', event)
}
Then, I've pushed data to a logic I've implemented upon incoming data like this.
socket_ch1.onmessage = async (event) => {
console.log( 'onmessage Ch1: ' + flag)
const parsedMessage = JSON.parse(event.data)
const keys = Object.keys(parsedMessage)
prpdch1.streamPush(parsedMessage[keys][0])
prpsch1.streamPush(parsedMessage[keys][0])
}
socket_ch2.onmessage = async (event) => {
console.log( 'onmessage Ch2: ' + flag)
const parsedMessage = JSON.parse(event.data)
const keys = Object.keys(parsedMessage)
prpsch2.streamPush(parsedMessage[keys][0])
prpdch2.streamPush(parsedMessage[keys][0])
}
streamPush() logic has been implemented as such :
streamPush( samples ){
console.log('prps streamPush : ' + this.name)
console.log(samples)
if(samples === undefined) return
let temp = []
// 7680 >> [128]
while(samples.length > 0 ) {
var cycle = samples.splice(0, this.dataSampleSize)
temp.push(cycle)
}
if(temp.length > 0)
this.databuf = this.databuf.concat(temp)
}
However, it seems data only come through one channel, and I don't know why. The following is the debugging console.
I think there is a problem with how I'm using the websocket. Can anyone spot the problem?
Thanks in advance!