'WebSocket object does not send messages after being set in an class
I'm trying to code a WebSocket application that will create a new instance of Client class when the authentication message was invoked. I pass the WebSocket object to Client, but when i try to send an message via Client class from the object, it doesn't send the message. I'm using ws libary on Mac OS 12.3.1. It dosen't give me any errors why is that occuring, nor warnings. Here is my code:
websocketData.clients[message.messageContent.username] = new Client(ws, message.messageContent.username);
class Client
{
constructor(socket, username)
{
this.ws = socket;
this.username = username;
console.log(this.ws);
setTimeout(() => {
this.ws.send(`{ data: "hello" }`);
}, 10000);
}
}
Does anyone know why is that happening? Is that behaviour alright or is it an error on my side? Cheers.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
