Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Ensure gamepad disconnect is triggered whenever a user navigates away…
Browse files Browse the repository at this point in the history
… from the player page
  • Loading branch information
Belchy06 committed Dec 12, 2023
1 parent d8a4e11 commit 606298d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Frontend/library/src/Inputs/GamepadController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export class GamePadController {
window.requestAnimationFrame
).bind(window);
const browserWindow = window as Window;

const onBeforeUnload = (ev: Event) =>
this.onBeforeUnload(ev);
window.addEventListener('beforeunload', onBeforeUnload);

if ('GamepadEvent' in browserWindow) {
const onGamePadConnected = (ev: GamepadEvent) =>
this.gamePadConnectHandler(ev);
Expand Down Expand Up @@ -253,6 +258,14 @@ export class GamePadController {
onGamepadDisconnected(controllerIdx: number) {
// Default Functionality: Do Nothing
}

onBeforeUnload(ev: Event) {
// When a user navigates away from the page, we need to inform UE of all the disconnecting
// controllers
for(const controller of this.controllers) {
this.onGamepadDisconnected(controller.id);
}
}
}


Expand Down

0 comments on commit 606298d

Please sign in to comment.