I would like to provide gamepad support for my web application. This application is a socket client (using socket.io) and it should also being able to deal with gamepad input.
So when plugging in a gamepad via USB or Bluetooth I would like to fire an event, same for input. I was hoping that the Gamepad API would solve it. Unfortunately it didn't.
I created this example
$(document).ready(() => {
window.addEventListener("gamepadconnected", e => {
console.log("connected gamepad");
});
window.addEventListener("gamepaddisconnected", e => {
console.log("disconnected gamepad");
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
I plug in my XBox360 controller but unfortunately no event was fired. Am I missing something?
I use Chrome Version 76.0.3809.132 (Official Build) on Manjaro Linux (64-bit)
When running navigator.getGamepads()
in the console I get this result GamepadList {0: null, 1: null, 2: null, 3: null, length: 4}
And btw. of course my controller is working on other applications e.g. games :)
Update
I installed Firefox 68.0.1 (64-bit) and it worked... but Chromium seems to struggle