in src/input.service.ts [476:512]
private pollGamepad(now: number) {
const rawpads = Array.from(navigator.getGamepads()).filter(pad => !!pad); // refreshes all checked-out gamepads
for (let i = 0; i < rawpads.length; i += 1) {
const pad = rawpads[i];
if (pad === null) {
continue;
}
const gamepad = this.gamepads[pad.id];
if (!gamepad) {
continue;
}
gamepad.pad = pad;
if (!gamepad.isConnected()) {
delete this.gamepads[pad.id];
continue;
}
if (this.keyboardVisible) {
continue;
}
directionNumsList.forEach(dir => {
const gamepadEvt = gamepad.events.get(dir);
if (gamepadEvt && gamepadEvt(now)) {
this.handleDirection(dir);
}
});
}
if (Object.keys(this.gamepads).length > 0) {
this.scheduleGamepadPoll();
} else {
this.pollRaf = null;
}
}