summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-11-19 02:53:23 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-11-19 04:07:01 +0100
commit91dbc288ccd7cab7d50feccba82ebfb99b5f2b69 (patch)
treeb05dce86f7b85f2efe20087d942716cb19f0de67
parentf13c7fc83e767da72accea125482fa130fb52cd3 (diff)
[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.
-rw-r--r--platform/javascript/js/libs/library_godot_input.js8
1 files changed, 6 insertions, 2 deletions
diff --git a/platform/javascript/js/libs/library_godot_input.js b/platform/javascript/js/libs/library_godot_input.js
index 5c7400d599..d85d0d5335 100644
--- a/platform/javascript/js/libs/library_godot_input.js
+++ b/platform/javascript/js/libs/library_godot_input.js
@@ -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);
},