Im connecting my backend to a thirdparty websocket. i want to reconnect whenever the socket is closed. I tried connecting again by listening to close event and re-initializing the dataWs again but it is not reconnecting.
Here is my service code:
`import {Injectable} from "@nestjs/common";
import { default as WebSocketClient, default as ws } from "ws";
import { EventListener, InjectWebSocketProvider, OnClose, OnOpen, OnError } from "nestjs-websocket";
@Injectable()
export class DataService {
constructor(
@InjectWebSocketProvider() private dataWs: WebSocketClient,
) {
this.initiate();
}
async initiate() {
setTimeout(() => this.connect(), 2000);
}
connect() {
if (this.dataWs.readyState == 1) {
console.log(" socket connection open!");
}
}
@EventListener("message")
async message(data) {
console.log("getting data", data)
}
}`