dualsense-ts
Version:
The natural interface for your DualSense Classic and DualSense Access controllers, with Typescript
60 lines • 2.73 kB
TypeScript
import { HIDProvider, DualsenseHIDState } from "./hid_provider";
export interface WebHIDProviderOptions {
/** Attach to this specific HIDDevice instead of discovering one */
device?: HIDDevice;
}
/** Callback invoked for each device selected via the WebHID permission dialog */
export type WebHIDDeviceCallback = (device: HIDDevice) => void;
export declare class WebHIDProvider extends HIDProvider {
device?: HIDDevice;
wireless?: boolean;
buffer?: DataView;
private readonly targetDevice?;
constructor(options?: WebHIDProviderOptions);
/**
* WebHID API doesn't indicate whether we are connected through the controller's
* USB or Bluetooth interface. The protocol is different depending on the connection
* type so we will try to detect it based on the collection information.
*/
detectConnectionType(): void;
/** Derive a stable identity string for a WebHID device */
private static deviceKey;
attach(device: HIDDevice): void;
/**
* Detach the current HIDDevice (if any) and attach a different one in place.
* Used by the manager to transplant a freshly-discovered device into an
* existing slot's provider after identity matching, so the consumer's
* Dualsense reference survives reconnection.
*
* The new device must already be open (or openable) — we close the old one,
* release its claim, and run the standard attach() flow on the new one.
*/
replaceDevice(device: HIDDevice): void;
/**
* You need to get HID device permissions from an interactive
* component, like a button. This returns a callback for triggering
* the permissions request.
*/
getRequest(): () => Promise<unknown>;
/**
* Request permission for multiple devices at once. Returns a callback
* suitable for use as an onClick handler. The `onDevice` callback is
* invoked once per selected device with the raw HIDDevice handle.
*/
static getMultiRequest(onDevice: WebHIDDeviceCallback, onError?: (error: Error) => void): () => Promise<void>;
/** List already-permitted Dualsense devices */
static enumerate(): Promise<HIDDevice[]>;
connect(): void;
get connected(): boolean;
disconnect(): void;
readFeatureReport(reportId: number): Promise<Uint8Array>;
sendFeatureReport(reportId: number, data: Uint8Array): Promise<void>;
/** Query the HID descriptor for the expected payload length of a feature report */
private getFeatureReportLength;
write(data: Uint8Array): Promise<void>;
process({ reportId, buffer, }: {
reportId: number;
buffer: DataView;
}): DualsenseHIDState;
}
//# sourceMappingURL=web_hid_provider.d.ts.map