websocket closed but not re opening

Viewed 28

im using websocket client in a route, so i send the payload to server like a publisher once i am done i will close the connection(.close()). that parts works fine on the first time. when i recall the route it just says the state is disconnectedenter code here and not re connecting

const WebSocket = require("ws");
const ws = new WebSocket(
  "my url"
);

class WebSoc {
//   constructor(assetType) {
//     this.assetType = assetType;
//   }

  handShake(assertType, desiredCapabilities, sessionId) {
    let readyState = ws.readyState;
    console.log("reconnecting.........", readyState); // firsttime this gives 1 // second time ehwn i call its just 3( means server closed)
    ws.send(
   "my content"
    );

  }

  push(sessionId, data) {
    let readyState = ws.readyState;
    console.log("reconnectindddd444444g.........", readyState); // firsttime this gives 1
    ws.send(
      "my content"
    );
    readyState = ws.readyState;
    console.log("reconnec555555555ting.........", readyState);// firsttime this gives 1
  }

  process(sessionId) {
    let readyState = ws.readyState;
    console.log("reconne6666666cting.........", readyState);// firsttime this gives 1
    ws.send(
      "my contetnt"
    );
    readyState = ws.readyState;
    console.log("reconn7777777ecting.........", readyState);// firsttime this gives 1
  }
  //ask how to stop
  goodbye() {
    let readyState = ws.readyState;

    console.log("closed.........", readyState);// firsttime this gives 1
    ws.close();

    readyState = ws.readyState;
    console.log("closed.........", readyState);// firsttime this gives 2
  }
}

module.exports = WebsocketStreamer;
0 Answers
Related