w3c / gamepad

Gamepad
https://w3c.github.io/gamepad/
Other
142 stars 48 forks source link

Vendor ID, product ID, name attributes #199

Open nondebug opened 7 months ago

nondebug commented 7 months ago

Gamepad identification relies on assumptions about browser-specific behaviors that are not defined as part of the spec. Gamepad API only exposes one device identifier for gamepads, the Gamepad.id string attribute. The content of this attribute is explicitly left unspecified. Each browser engine uses a different naming scheme.

Chromium typically includes the product name string and 16-bit hexadecimal values for the vendor and product ID. If Gamepad.mapping is "standard" then Chromium also includes a "STANDARD GAMEPAD" tag:

Wireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 09cc)

Firefox includes the product name string and hexadecimal vendor/product ID values:

054c-09cc-Wireless Controller

Safari only includes the product name, which may be rewritten by the OS. If the gamepad is a GCExtendedGamepad (roughly equivalent to Standard Gamepad) then it includes an "Extended Gamepad" tag:

DUALSHOCK4 Wireless Controller Extended Gamepad

Currently, applications that want to make use of the product name or vendor/product IDs must parse them out of the Gamepad.id string. Gamepad API should provide these identifiers as separate attributes on the Gamepad object and specify their values so they can be used consistently across different browser engines:

partial interface Gamepad {
  // The vendor ID of this gamepad, or null if the gamepad does not have a vendor ID.
  readonly attribute unsigned long? vendorId;
  // The product ID of this gamepad, or null if the gamepad does not have a product ID.
  readonly attribute unsigned long? productId;
  // A non-empty human-readable name representing this gamepad.
  readonly attribute DOMString name;
};

Vendor & product ID attributes

Vendor IDs are allocated by the USB-IF and Bluetooth SIG. Product IDs are assigned by the manufacturer. These values are typically used to programmatically identify a device, for instance when the operating system selects a device driver.

Web applications use these IDs to identify the gamepad model and provide a more accurate representation of the gamepad and its inputs. For instance, an application may use alternate button icons that match the labels on the gamepad's buttons.

Vendor ID and product ID should be optional attributes. Typically only USB and Bluetooth devices have assigned vendor IDs; Gamepad API should not assume gamepads use a particular transport or protocol. Also, even for devices that have vendor/product IDs, those IDs may not be accessible when accessing the device through the platform's gamepad API. User agents may choose not to expose these IDs in some or all contexts in order to mitigate fingerprinting.

Name attribute

The name attribute is intended for use only as a human-facing identifier. Since it is intended to be readable by humans, it should never be empty or null. Typically the value should match the name the manufacturer assigned to the gamepad, but if there is no manufacturer-assigned name (or it cannot be accessed) then the user agent should create a suitable name.

The content of the name attribute cannot be fully specified because it relies on platform behaviors. For instance, on some platforms the device name reported through the platform API only includes the product name (example: "Wireless Controller") while on some platforms it may also include the manufacturer name (example: "Sony Interactive Entertainment Wireless Controller"). The browser is not in control of how these names are generated and cannot assume the name provided by the platform matches the manufacturer-assigned name.

The spec should make it clear that the Gamepad.name attribute is not a stable identifier and is only guaranteed to stay the same as long as the gamepad remains connected. The name may change over time due to browser updates, OS updates, or device firmware updates.