in src/input.service.ts [425:460]
private watchForGamepad() {
const addGamepad = (pad: Gamepad | null) => {
let gamepad: IGamepadWrapper | null = null;
if (pad === null) {
return;
}
if (/xbox/i.test(pad.id)) {
gamepad = new XboxGamepadWrapper(pad);
}
if (!gamepad) {
// We can try, at least ¯\_(ツ)_/¯ and this should
// usually be OK due to remapping.
gamepad = new XboxGamepadWrapper(pad);
}
this.gamepads[pad.id] = gamepad;
};
Array.from(navigator.getGamepads())
.filter(pad => !!pad)
.forEach(addGamepad);
if (Object.keys(this.gamepads).length > 0) {
this.scheduleGamepadPoll();
}
this.subscriptions.push(
merge(this.gamepadSrc, fromEvent(window, 'gamepadconnected')).subscribe(ev => {
addGamepad((<any>ev).gamepad);
if (this.pollRaf) {
cancelAnimationFrame(this.pollRaf);
}
this.scheduleGamepadPoll();
}),
);
}