I'm using a websocket with React, I'm connecting to it and when I try to get data from the server with on message, I receive multiple object and I cannot handle them. my code:
const chatSocket = new WebSocket(`wss://myurl/${key}/${user.id}`)
chatSocket.onopen = (e) => {
console.log("[open] Connection established");
chatSocket.send({
'type': 'online_users'
})
}
chatSocket.onmessage = (e) => {
const message = JSON.parse(e.data);
console.log(message);
}
what I receive:
I'm trying to access the data in the type : 'online_users'.
I tried to push everything in one array, did not work and by calling:
console.log(message.type);
console.log(message.data);
console.log(message[0]);
it does not work either.
Thanks.