安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
USBEndpoint
接口在
WebUSB API
provides information about an endpoint provided by the USB device. An endpoint represents a unidirectional data stream into or out of a device.
USBEndpoint.USBEndpoint
USBEndpoint
object which will be populated with information about the endpoint on the provided
USBAltenateInterface
with the given endpoint number and transfer direction.
USBEndpoint.endpointNumber
bEndpointAddress
field of the endpoint descriptor defining this endpoint. This value is used to identify the endpoint when calling methods on
USBDevice
.
USBEndpoint.direction
"in"
- Data is transferred from device to host.
"out"
- Data is transferred from host to device.
USBEndpoint.type
"bulk"
- Provides reliable data transfer for large payloads. Data sent through a bulk endpoint is guaranteed to be delivered or generate an error but may be preempted by other data traffic.
"interrupt"
- Provides reliable data transfer for small payloads. Data sent through an interrupt endpoint is guaranteed to be delivered or generate an error and is also given dedicated bus time for transmission.
"isochronous"
- Provides unreliable data transfer for payloads that must be delivered periodically. They are given dedicated bus time but if a deadline is missed the data is dropped.
USBEndpoint.packetSize
Returns the size of the packets that data sent through this endpoint will be divided into.
While sometimes the developer knows ahead of time the exact layout of a device's endpoints there are cases where this must be discovered at runtime. For example, a USB serial device must provide bulk input and output endpoints but their endpoint numbers will depend on what other interfaces the device provides.
This code identifies the correct endpoints by searching for the interface implementing the USB CDC interface class and then identifying the candidate endpoints based on their type and direction.
let inEndpoint = undefined;
let outEndpoint = undefined;
for (const interface of device.configuration.interfaces) {
// Only support devices with out multiple alternate interfaces.
const alternate = interface.alternates[0];
// Identify the interface implementing the USB CDC class.
const USB_CDC_CLASS = 10;
if (alternate.interfaceClass != USB_CDC_CLASS) {
continue;
}
for (const endpoint of alternate.endpoints) {
// Identify the bulk transfer endpoints.
if (endpoint.type != "bulk") {
continue;
}
if (endpoint.direction == "in") {
inEndpoint = endpoint.endpointNumber;
} else if (endpoint.direction == "out") {
outEndpoint = endpoint.endpointNumber;
}
}
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebUSB
The definition of 'USBEndPoint' in that specification. |
草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
USBEndpoint
|
Chrome 61 | Edge 79 | Firefox No | IE No | Opera 48 | Safari No | WebView Android No | Chrome Android 61 | Firefox Android No | Opera Android 45 | Safari iOS No | Samsung Internet Android 8.0 |
USBEndpoint()
构造函数
|
Chrome 61 | Edge 79 | Firefox No | IE No | Opera 48 | Safari No | WebView Android No | Chrome Android 61 | Firefox Android No | Opera Android 45 | Safari iOS No | Samsung Internet Android 8.0 |
direction
|
Chrome 61 | Edge 79 | Firefox No | IE No | Opera 48 | Safari No | WebView Android No | Chrome Android 61 | Firefox Android No | Opera Android 45 | Safari iOS No | Samsung Internet Android 8.0 |
endpointNumber
|
Chrome 61 | Edge 79 | Firefox No | IE No | Opera 48 | Safari No | WebView Android No | Chrome Android 61 | Firefox Android No | Opera Android 45 | Safari iOS No | Samsung Internet Android 8.0 |
packetSize
|
Chrome 61 | Edge 79 | Firefox No | IE No | Opera 48 | Safari No | WebView Android No | Chrome Android 61 | Firefox Android No | Opera Android 45 | Safari iOS No | Samsung Internet Android 8.0 |
type
|
Chrome 61 | Edge 79 | Firefox No | IE No | Opera 48 | Safari No | WebView Android No | Chrome Android 61 | Firefox Android No | Opera Android 45 | Safari iOS No | Samsung Internet Android 8.0 |
完整支持
不支持
实验。期望将来行为有所改变。