#Auto reconnect in nestjs-websocket

1 messages · Page 1 of 1 (latest)

pliant ocean
#

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)
}

}`

vague pasture
#

@stone temple maybe you have a tip?

stone temple
#

Hi

#

I have an open issue with this. I am testing a few options right now. I will probably release a new version this week

pliant ocean
#

Can you post the issue link here, so we can track it

vague pasture