Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Illegal Constructor #83

Open
MasterCodeIT opened this issue Jun 24, 2021 · 6 comments
Open

TypeError: Illegal Constructor #83

MasterCodeIT opened this issue Jun 24, 2021 · 6 comments

Comments

@MasterCodeIT
Copy link

Anyone run into this issue?

Using the coding from your selector.js. I added a connect button to execute but keep running into this pop-up error when executing. Thoughts?

@thegecko
Copy link
Owner

You added a button and see a popup, where are you running the library?

@MasterCodeIT
Copy link
Author

MasterCodeIT commented Jun 24, 2021

const devicesFound = devices => new Promise(resolve => {
    process.stdin.setRawMode(true);
    process.stdin.setEncoding("utf8");
    process.stdin.on("readable", () => {
        const input = process.stdin.read();

        if (input === "\u0003") {
            process.exit();
        } else {
            const index = parseInt(input);
            if (index && index <= devices.length) {
                process.stdin.setRawMode(false);
                resolve(devices[index - 1]);
            }
        }
    });

    console.log("select a device to see it's active configuration:");
    devices.forEach((device, index) => {
        console.log(`${index + 1}: ${device.productName || device.serialNumber}`);
    });
});

const startDevice = async () => {
   const usb = new USB({
      devicesFound
  });

  (async () => {
      try {
          const device = await usb.requestDevice({
              filters: [{vendorId: 0x0781}, {productId: 0xD437}]
          });

          console.log(JSON.stringify(device, (key, value) => {
              if (key === "interfaces") return `[${value.length}...]`;
              return value;
          }, "\t"));
      } catch (error) {
          console.log(error.message);
      }
  })
await device.open();

just used query selector

const initEvents = () => {document.querySelector('#connect').addEventListener('click', async () => {
    try {device = await startDevice()}

@thegecko
Copy link
Owner

You're running this in a browser?
You should use the native webusb.

@MasterCodeIT
Copy link
Author

Using electron

@thegecko
Copy link
Owner

Not tried it, but I believe you need to run this in the backend process in Electron.

@gniezen
Copy link

gniezen commented Aug 26, 2021

@MasterCodeIT How are you importing/requiring the library? Usually it's not necessary to instantiate the class like you did in

const usb = new USB({
      devicesFound
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants