Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add WebUSB WebIDL #1712

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,32 @@ UiEvent = []
UiEventInit = []
Url = []
UrlSearchParams = []
USB = []
USBConnectionEvent = []
USBConnectionEventInit = []
USBDeviceFilter = []
USBDevice = []
USBDeviceRequestOptions = []
USBRequestType = []
USBRecipient = []
USBTransferStatus = []
USBControlTransferParameters = []
USBInTransferResult = []
USBOutTransferResult = []
USBIsochronousInTransferPacket = []
USBIsochronousInTransferResult = []
USBIsochronousOutTransferPacket = []
USBIsochronousOutTransferResult = []
USBConfiguration = []
USBInterface = []
USBAlternateInterface = []
USBDirection = []
USBEndpointType = []
USBEndpoint = []
USBPermissionDescriptor = []
AllowedUSBDevice = []
USBPermissionStorage = []
USBPermissionResult = []
UserProximityEvent = []
UserProximityEventInit = []
UserVerificationRequirement = []
Expand Down
248 changes: 248 additions & 0 deletions crates/web-sys/webidls/enabled/WebUSB.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
// GENERATED CONTENT - DO NOT EDIT
// Content was automatically extracted by Reffy into reffy-reports
// (https://github.com/tidoust/reffy-reports)
// Source: WebUSB API (https://wicg.github.io/webusb/)

dictionary USBDeviceFilter {
unsigned short vendorId;
unsigned short productId;
octet classCode;
octet subclassCode;
octet protocolCode;
DOMString serialNumber;
};

dictionary USBDeviceRequestOptions {
required sequence<USBDeviceFilter> filters;
};

[Exposed=(DedicatedWorker,SharedWorker,Window), SecureContext]
interface USB : EventTarget {
attribute EventHandler onconnect;
attribute EventHandler ondisconnect;
Promise<sequence<USBDevice>> getDevices();
[Exposed=Window] Promise<USBDevice> requestDevice(USBDeviceRequestOptions options);
};

[Exposed=Window, SecureContext]
partial interface Navigator {
[SameObject] readonly attribute USB usb;
};

[Exposed=(DedicatedWorker,SharedWorker), SecureContext]
partial interface WorkerNavigator {
[SameObject] readonly attribute USB usb;
};

dictionary USBConnectionEventInit : EventInit {
required USBDevice device;
};

[
Constructor(DOMString type, USBConnectionEventInit eventInitDict),
Exposed=(DedicatedWorker,SharedWorker,Window),
SecureContext
]
interface USBConnectionEvent : Event {
[SameObject] readonly attribute USBDevice device;
};

[Exposed=(DedicatedWorker,SharedWorker,Window), SecureContext]
interface USBDevice {
readonly attribute octet usbVersionMajor;
readonly attribute octet usbVersionMinor;
readonly attribute octet usbVersionSubminor;
readonly attribute octet deviceClass;
readonly attribute octet deviceSubclass;
readonly attribute octet deviceProtocol;
readonly attribute unsigned short vendorId;
readonly attribute unsigned short productId;
readonly attribute octet deviceVersionMajor;
readonly attribute octet deviceVersionMinor;
readonly attribute octet deviceVersionSubminor;
readonly attribute DOMString? manufacturerName;
readonly attribute DOMString? productName;
readonly attribute DOMString? serialNumber;
readonly attribute USBConfiguration? configuration;
readonly attribute FrozenArray<USBConfiguration> configurations;
readonly attribute boolean opened;
Promise<void> open();
Promise<void> close();
Promise<void> selectConfiguration(octet configurationValue);
Promise<void> claimInterface(octet interfaceNumber);
Promise<void> releaseInterface(octet interfaceNumber);
Promise<void> selectAlternateInterface(octet interfaceNumber, octet alternateSetting);
Promise<USBInTransferResult> controlTransferIn(USBControlTransferParameters setup, unsigned short length);
Promise<USBOutTransferResult> controlTransferOut(USBControlTransferParameters setup, optional BufferSource data);
Promise<void> clearHalt(USBDirection direction, octet endpointNumber);
Promise<USBInTransferResult> transferIn(octet endpointNumber, unsigned long length);
Promise<USBOutTransferResult> transferOut(octet endpointNumber, BufferSource data);
Promise<USBIsochronousInTransferResult> isochronousTransferIn(octet endpointNumber, sequence<unsigned long> packetLengths);
Promise<USBIsochronousOutTransferResult> isochronousTransferOut(octet endpointNumber, BufferSource data, sequence<unsigned long> packetLengths);
Promise<void> reset();
};

enum USBRequestType {
"standard",
"class",
"vendor"
};

enum USBRecipient {
"device",
"interface",
"endpoint",
"other"
};

enum USBTransferStatus {
"ok",
"stall",
"babble"
};

dictionary USBControlTransferParameters {
required USBRequestType requestType;
required USBRecipient recipient;
required octet request;
required unsigned short value;
required unsigned short index;
};

[
Constructor(USBTransferStatus status, optional DataView? data),
Exposed=(DedicatedWorker,SharedWorker,Window),
SecureContext
]
interface USBInTransferResult {
readonly attribute DataView? data;
readonly attribute USBTransferStatus status;
};

[
Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0),
Exposed=(DedicatedWorker,SharedWorker,Window),
SecureContext
]
interface USBOutTransferResult {
readonly attribute unsigned long bytesWritten;
readonly attribute USBTransferStatus status;
};

[
Constructor(USBTransferStatus status, optional DataView? data),
Exposed=(DedicatedWorker,SharedWorker,Window),
SecureContext
]
interface USBIsochronousInTransferPacket {
readonly attribute DataView? data;
readonly attribute USBTransferStatus status;
};

[
Constructor(sequence<USBIsochronousInTransferPacket> packets, optional DataView? data),
Exposed=(DedicatedWorker,SharedWorker,Window),
SecureContext
]
interface USBIsochronousInTransferResult {
readonly attribute DataView? data;
readonly attribute FrozenArray<USBIsochronousInTransferPacket> packets;
};

[
Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0),
Exposed=(DedicatedWorker,SharedWorker,Window),
SecureContext
]
interface USBIsochronousOutTransferPacket {
readonly attribute unsigned long bytesWritten;
readonly attribute USBTransferStatus status;
};

[
Constructor(sequence<USBIsochronousOutTransferPacket> packets),
Exposed=(DedicatedWorker,SharedWorker,Window),
SecureContext
]
interface USBIsochronousOutTransferResult {
readonly attribute FrozenArray<USBIsochronousOutTransferPacket> packets;
};

[
Constructor(USBDevice device, octet configurationValue),
Exposed=(DedicatedWorker,SharedWorker,Window),
SecureContext
]
interface USBConfiguration {
readonly attribute octet configurationValue;
readonly attribute DOMString? configurationName;
readonly attribute FrozenArray<USBInterface> interfaces;
};

[
Constructor(USBConfiguration configuration, octet interfaceNumber),
Exposed=(DedicatedWorker,SharedWorker,Window),
SecureContext
]
interface USBInterface {
readonly attribute octet interfaceNumber;
readonly attribute USBAlternateInterface alternate;
readonly attribute FrozenArray<USBAlternateInterface> alternates;
readonly attribute boolean claimed;
};

[
Constructor(USBInterface deviceInterface, octet alternateSetting),
Exposed=(DedicatedWorker,SharedWorker,Window),
SecureContext
]
interface USBAlternateInterface {
readonly attribute octet alternateSetting;
readonly attribute octet interfaceClass;
readonly attribute octet interfaceSubclass;
readonly attribute octet interfaceProtocol;
readonly attribute DOMString? interfaceName;
readonly attribute FrozenArray<USBEndpoint> endpoints;
};

enum USBDirection {
"in",
"out"
};

enum USBEndpointType {
"bulk",
"interrupt",
"isochronous"
};

[
Constructor(USBAlternateInterface alternate, octet endpointNumber, USBDirection direction),
Exposed=(DedicatedWorker,SharedWorker,Window),
SecureContext
]
interface USBEndpoint {
readonly attribute octet endpointNumber;
readonly attribute USBDirection direction;
readonly attribute USBEndpointType type;
readonly attribute unsigned long packetSize;
};

dictionary USBPermissionDescriptor : PermissionDescriptor {
sequence<USBDeviceFilter> filters;
};

dictionary AllowedUSBDevice {
required octet vendorId;
required octet productId;
DOMString serialNumber;
};

dictionary USBPermissionStorage {
sequence<AllowedUSBDevice> allowedDevices = [];
};

interface USBPermissionResult : PermissionStatus {
attribute FrozenArray<USBDevice> devices;
};