Selkies
Developer ReferenceWeb client coreLib

lib/gamepad

Gamepad polling for the streaming cores: reads navigator.getGamepads() on a fixed interval and reports button and axis changes in the standard layout.

Pads the browser could not map to the standard layout are remapped through the per-platform profile database that gendb.js generates: raw button and axis indices differ across platforms for the same pad, so the lookup is scoped to the platform this browser runs on, and anything unmatched (ChromeOS, the BSDs) uses the evdev layout Linux browsers report. Such pads also carry the D-pad on axes 4 and 5, which is translated to the standard buttons 12 to 15.

Classes

GamepadManager

Defined in: lib/gamepad.js:57

Polls every connected pad and reports changes through callbacks.

Polling starts in the constructor and runs until destroy; enable and disable pause it without losing per-pad state.

Constructors

Constructor
new GamepadManager(
   gamepad, 
   onButton, 
   onAxis, 
   onHeld
): GamepadManager;

Defined in: lib/gamepad.js:68

Parameters
ParameterTypeDescription
gamepadGamepadPad the manager was created for, kept for the caller.
onButton(index, button, value, pressed) => voidCalled with the pad slot and standard-layout button index on every change.
onAxis(index, axis, value) => voidCalled with the pad slot and standard-layout axis index on every change.
onHeld() => voidCalled about ten times a second while any control is away from rest, so the server can neutralize a held pad whose client died without a transport close.
Returns

GamepadManager

Properties

gamepad
gamepad: Gamepad;

Defined in: lib/gamepad.js:69

onButton
onButton: (index, button, value, pressed) => void;

Defined in: lib/gamepad.js:70

Parameters
ParameterType
indexnumber
buttonnumber
valuenumber
pressedboolean
Returns

void

onAxis
onAxis: (index, axis, value) => void;

Defined in: lib/gamepad.js:71

Parameters
ParameterType
indexnumber
axisnumber
valuenumber
Returns

void

onHeld
onHeld: () => void;

Defined in: lib/gamepad.js:72

Returns

void

state
state: object;

Defined in: lib/gamepad.js:74

interval
interval: number;

Defined in: lib/gamepad.js:76

Methods

enable()
enable(): void;

Defined in: lib/gamepad.js:82

Resumes polling.

Returns

void

disable()
disable(): void;

Defined in: lib/gamepad.js:90

Pauses polling; the per-pad state is kept.

Returns

void

destroy()
destroy(): void;

Defined in: lib/gamepad.js:294

Stops polling and forgets every pad.

Returns

void

Variables

GP_TIMEOUT

const GP_TIMEOUT: 16 = 16;

Defined in: lib/gamepad.js:38

Poll interval in milliseconds.

On this page

Edit on GitHub