[HTML5] Add checks to Gamepad API events.

In some conditions the events might be generated even when the `gamepad`
object is not accessible due to Security Context requirements.
This commit adds a check to avoid firing the handler in those cases.

(cherry picked from commit 91dbc288cc)
This commit is contained in:
Fabio Alessandrelli 2021-11-19 02:53:23 +01:00 committed by Rémi Verschelde
parent 1066b60781
commit f56b1a5af5
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -104,10 +104,14 @@ const GodotInputGamepads = {
}
}
GodotEventListeners.add(window, 'gamepadconnected', function (evt) {
add(evt.gamepad);
if (evt.gamepad) {
add(evt.gamepad);
}
}, false);
GodotEventListeners.add(window, 'gamepaddisconnected', function (evt) {
onchange(evt.gamepad.index, 0);
if (evt.gamepad) {
onchange(evt.gamepad.index, 0);
}
}, false);
},