HIDDevice: phương thức forget()
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Note: This feature is available in Web Workers, except for Shared Web Workers.
Phương thức forget() của giao diện HIDDevice đóng kết nối đến thiết bị HID và xóa bộ nhớ về thiết bị.
Cú pháp
forget()
Tham số
Không có.
Giá trị trả về
Một Promise được giải quyết với giá trị undefined khi kết nối đã đóng, thiết bị đã bị quên và quyền đã được đặt lại.
Ví dụ
Trong ví dụ sau, chúng ta kết nối đến thiết bị HID Nintendo Switch Joy-Con Right, nhấp nháy một lần rồi ngắt kết nối.
async function blink() {
const devices = await navigator.hid.requestDevice({
filters: [
{
vendorId: 0x057e, // Nintendo Co., Ltd
productId: 0x2007, // Joy-Con Right
},
],
});
const device = devices[0];
await device.open();
// Turn off
await device.sendFeatureReport(reportId, Uint32Array.from([0, 0]));
await new Promise((resolve) => setTimeout(resolve, 100));
// Turn on
await device.sendFeatureReport(reportId, Uint32Array.from([512, 0]));
await new Promise((resolve) => setTimeout(resolve, 100));
// Finally, disconnect from it
await device.forget();
}
blink();
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| WebHID API> # dom-hiddevice-forget> |