Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Using usb-detection with electron #137

Open
sensslen opened this issue Apr 4, 2021 · 4 comments
Open

Using usb-detection with electron #137

sensslen opened this issue Apr 4, 2021 · 4 comments
Labels

Comments

@sensslen
Copy link

sensslen commented Apr 4, 2021

Hi there, I am trying to use usb-detection in combination with electron. I do have rebuilt using electron-rebuild but when executing usb-detection functions I get:

Worker Thread error Error: Module did not self-register: '\\?\D:\GIT\Private\Cgf.CameraControl.Main.Gui\.webpack\main\native_modules\build\Release\detection.node'.
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1138:18)
    at Module.load (internal/modules/cjs/loader.js:935:32)
    at Function.Module._load (internal/modules/cjs/loader.js:776:14)
    at Module.require (internal/modules/cjs/loader.js:959:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object../node_modules/usb-detection/index.js (D:\GIT\Private\Cgf.CameraControl.Main.Gui\.webpack\main\index.js:124741:18)
    at __webpack_require__ (D:\GIT\Private\Cgf.CameraControl.Main.Gui\.webpack\main\index.js:21:30)
    at Object../node_modules/@sensslen/node-gamepad/NodeGamepad.js (D:\GIT\Private\Cgf.CameraControl.Main.Gui\.webpack\main\index.js:4116:23)
    at __webpack_require__ (D:\GIT\Private\Cgf.CameraControl.Main.Gui\.webpack\main\index.js:21:30)
    at Object../node_modules/@sensslen/node-gamepad/index.js (D:\GIT\Private\Cgf.CameraControl.Main.Gui\.webpack\main\index.js:4384:21)

Please feel free to check out the code that produces the issue here: https://github.com/sensslen/Cgf.CameraControl.Main.Gui

Get the issue by going to file->LoadConfiguration loading the following dummy file:

{
  "cams": [
    {
      "type": "PtzLancCamera",
      "instance": 1,
      "ConnectionUrl": "http://1.2.3.4:5001",
      "ConnectionPort": "/dev/ttyACM0"
    }
  ],
  "videoMixers": [
    {
      "type": "blackmagicdesign/Atem",
      "instance": 1,
      "IP": "1.2.3.2",
      "CameraConnections": {
        "1": 1
      }
    }
  ],
  "interfaces": [
    {
      "type": "logitech/F310",
      "instance": 1,
      "VideoMixer": {
        "Connection": 1,
        "MixBlock": 0
      },
      "ConnectionChange": {
        "Default": {
          "up": 1,
          "right": 2,
          "down": 3,
          "left": 4
        }
      },
      "SpecialFunction": {
        "Default": {
        }
      }
    }
  ]
}

I am currently stuck. Any help would be highly appreciated!

@MadLittleMods
Copy link
Owner

Which version of Electron are you using?

Have you tried any of the solutions from a Google, module did not self-register electron?

I see that you tried using electron-rebuild.


this is a generic error that usually suggests there's a mismatch between the target platform the native module is built against and the version of Electron being used.

atom/node-keytar#215 (comment)

Possible solution from the same thread: atom/node-keytar#215 (comment)

Other than what you can already find on Google, I don't have any insight on using this with Electron.

@sensslen
Copy link
Author

sensslen commented Apr 6, 2021

The problem apparently has to do with the way electron loads native modules. This electron/electron#18397 post describes this issue. The Issue I describe has to do with the fact that usb-detection is simply not compatible with electron at the moment.

@adkairalla
Copy link

adkairalla commented Apr 6, 2021

I did manage to make usb-detection work with electron (had other issues with the way the react flow works) without major incidents. I did a regular npm install usb-detection inside my package, which added it to the package.json as a dependency and had to create a symbolic link in the package.json folder because the bindings package was looking for the .node file in the wrong place. Also had to run the electron-rebuild command for the usb-detection package.

With those fixes, I managed to make it work inside electron, but I did have issues because I'm not mainly a react programmer and I don't quite understand the concept of the updates and generation of components, so I ended up creating multiple USB listeners each time the page reloaded, hehehe. Hope this helps!

@mcous
Copy link
Contributor

mcous commented Oct 19, 2021

@sensslen I'm happy to report usb-detection is very much compatible with Electron! We have been using it in the Opentrons App for more than a year (starting with [email protected]). Currently running it on Electron v13. We run usb-detection in the main process, not the renderer process.

Feel free to hit me up the the usb-detection gitter if you're looking for advice about how we use usb-detection in the Opentrons App. I can't speak for the development of the package itself, but I can speak as a user of the package.

If this ticket is specifically about using usb-detection in the renderer process, I'd say it's a duplicate of #102

@MadLittleMods MadLittleMods changed the title using usb-detection with electron Using usb-detection with electron Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants