Gamepad API - Does a Gamepad Object persist after disconnect and reused on reconnect?

454 views Asked by At

Summary:
I want to tell the difference between two or more 'XBox 360 Controllers'.

Context:
I'm working on building a GamepadManager for the Gamepad API using Javascript (Typescript). The GamepadManager's main function is to support Callbacks which are called when Specific Gamepad Buttons or Axes are used. (GamepadManager also uses a list of Controller Profiles which specifically map-out Button and Axes for particular Make & Models)


Question:
When a Physical Gamepad is reconnected, can the SAME Javascript Gamepad Object be relinked/assigned again to the originally disconnected Physical Gamepad?
Might that actually be happening automatically? Better yet, can relinking somehow be done Manually?

window.addEventListener("gamepaddisconnected", function(e) {
    var gp = e.gamepad;
    var isConnected = gp.connected;
});


Senario:
When a Physical Gamepad is disconnected, the above EventListener will return an Event which contains the Gamepad Object originally used for the now disconnected Physical Gamepad. The Event's Gamepad Object has a boolean to specify if the Physical Gamepad is still connected or not.... but of course it's disconnected since it's been returned from the disconnection event listener. To me, that implies the Gamepad Object may be used persistently while that Physical Gamepad remains disconnected, perhaps to be reused when it is Reconnected again.

What I'm Looking For:
I want my GamepadManager to be be smart enough to link a reconnected Physical Gamepad to the SAME In-Game Playable Character before it was disconnected.
(this way, if a player is using a specific controller, and it is disconnected and reconnected, that same controller is remembered and will still control the same character)

Furthermore, I want it so even if All 4 Physical Gamepads are the same make/model of XBox 360 Controller, the GamepadManager would be able to tell the difference, regardless of the USB Ports they are connected to.

Might there be a specific ID/Serial Number that each Physical Gamepad has to differentiate themselves from other Gamepads of the same Make and Model? or is the USB Port the only way to tell the difference between 2 or more matching Physical Gamepads?

Alternatively:
Is there a better way of looking at how to manage Physical Gamepads for a game? (Side-scrolling Action Sandbox)

0

There are 0 answers