@hcodes/webhid-ds4
    Preparing search index...

    Class DualShock4

    Main class.

    Hierarchy

    • EventTarget
      • DualShock4
    Index
    audio: DualShock4Audio = ...

    Hardware audio levels and optional browser headphone playback/microphone capture.

    firmwareInfo: DualShock4FirmwareInfo | null = null

    Firmware metadata reported by the connected controller, or null when unavailable.

    isClone: boolean | null = null

    Sony certificate and random-challenge signature check over USB or Bluetooth. false means both signatures verified, true means a signature failed. null means unknown (pending, unsupported, I/O failure or timeout). Background completion emits clonecheck after this field is updated. Copied authentic controller keys cannot be distinguished by this check.

    lastReport?: ArrayBuffer

    Raw contents of the last HID Report sent by the controller.

    lastSentReport?: ArrayBuffer

    Raw contents of the last HID Report sent to the controller.

    lightbar: default = ...

    Allows lightbar control

    rumble: default = ...

    Allows rumble control

    state: DualShock4State = ...

    Current controller state

    • get device(): HIDDevice | undefined

      Internal WebHID device

      Returns HIDDevice | undefined

    • set device(device: HIDDevice | undefined): void

      Parameters

      • device: HIDDevice | undefined

      Returns void

    • get isCloneChecking(): boolean

      Whether background authentication is running for the current controller. False before starting, after completion (including an unknown result), and immediately after cancellation. Already false in clonecheck listeners.

      Returns boolean

    • The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

      MDN Reference

      Type Parameters

      Parameters

      Returns void

    • Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | AddEventListenerOptions

      Returns void

    • Requests access to a controller and opens its WebHID session.

      This function must be called in the context of user interaction (i.e in a click event handler), otherwise it might not work. Firmware reading is bounded by one second; authentication runs in the background and does not delay connection or the connect event.

      Returns Promise<boolean>

      true when the controller is connected, or false when device selection is cancelled.

    • Stops rumble and closes the current WebHID session without revoking device permission. Pending output that is waiting for transport detection rejects with an AbortError.

      If the browser fails to close a device that remains open, the active session is restored and the error is rethrown so disconnection can be retried.

      Returns Promise<void>

    • Reads DualShock 4 feature report 0xA3, updates firmwareInfo, and starts background authentication without waiting for its result.

      Both USB and Bluetooth controllers use this report. The firmware request times out after one second. A separate authentication exchange using 0xF0/0xF2/0xF1 verifies the Sony certificate and challenge signature, with a total 30-second deadline. Concurrent checks share one exchange. While pending, isCloneChecking is true and isClone is null; completion updates it and emits clonecheck. Subscribe before connecting or refreshing to observe results. Unsupported, timed out, or malformed firmware reports return null; authentication failures do not prevent compatible controllers connecting.

      Returns Promise<DualShock4FirmwareInfo | null>

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

      MDN Reference

      Type Parameters

      Parameters

      Returns void

    • Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | EventListenerOptions

      Returns void

    • Sends the local rumble, lightbar and configured hardware volumes to the controller.

      This function is called automatically in most cases. Output requested before the first supported input report is combined and sent once the interface is known.

      Returns Promise<void>