HIDDevice: forget() 方法
注意:此功能在 Web Workers 中可用,但 共享 Web Workers 除外。
HIDDevice 介面的 forget() 方法會關閉與 HID 裝置的連線並忘記該裝置。
語法
js
forget()
引數
無。
返回值
一個 Promise,一旦連線關閉、裝置被忘記且許可權被重置,它就會以 undefined 解析。
示例
在下面的示例中,我們連線到一個 Nintendo Switch Joy-Con Right HID 裝置,閃爍一次,然後斷開連線。
js
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();
規範
| 規範 |
|---|
| WebHID API # dom-hiddevice-forget |
瀏覽器相容性
載入中…