Error when using Controller.js for Gamepad support, but only with Electron?


#1

I have been trying to add gamepad support to an electron app I am writing and have found that a lot of libs for gamepads, and even the gamepad API, don’t work correctly.

I am specifically trying to use this lib https://samiare.github.io/Controller.js/ for controller support, only because it maps analog sticks to dpad events (which is essential for what I am doing). However the lib throws errors only while in Electron. I copied the opened the same code in my browser and it worked as expected, no errors.

Anyone got any ideas on what might be causing this or a way to fix it (either a fix in Electron or an alternative lib)? Like I said I’ve tried other libs and they are almost all broken in some way as well, which leads me to believe it’s the gamepad API that’s the underlying problem here.


#2

What are the errors you’re getting?


#3
Uncaught TypeError: Cannot read property 'buttons' of null
    at Controller.loopThroughButtons (Controller.js:232)
    at Controller.checkInputs (Controller.js:38)
    at Controller.updateController (Controller.js:32)

Only fires when in Electron, not in the browser. I think it’s caused by the gamepaddisconnected event not being sent while using Electron (or at least I could never get it to).

I ended up fixing the issue partially by editing the source and adding a try-catch, but it’s more of just a rough hack than a proper fix. The error doesn’t display but none of the disconnect events fire (which is why I assume it’s an issue with gamepaddisconnected)