Javascript.NodeJS icon indicating copy to clipboard operation
Javascript.NodeJS copied to clipboard

Event Listener on nodejs

Open duduccosta opened this issue 3 years ago • 1 comments

Hi.

I'm trying to use a lib that works with events. In my first implementation, it worked.

I have this code:

const { Client } = require("listeners.js");
const client = new Client();

module.exports = (callback) => {
  try {
    let qrCode = "";
    client.on("qr", (qr) => {
      qrCode = qr;
      callback(null, qrCode);
    });

    client.on("ready", () => {
      console.log("Client is ready!");
    });

    client.on("message", (message) => {
      console.log(message);
    });

    client.initialize();

  } catch (error) {
    callback(error, null);
  }
};

I need to listen those events some how. When i execute InvokeFromStringAsync once, it work. I can get the qrcode string. But the thread is ended.

Is there some way to keep listening the script, and some how pass the event data to c# code?

Thanks.

duduccosta avatar Jul 15 '22 06:07 duduccosta

Sorry for the slow response. You could read from stdout: I want to subscribe to events.

JeremyTCD avatar Jul 18 '22 04:07 JeremyTCD