HIDDevice.sendReport()

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

HIDDevice インターフェイスの sendReport() メソッドは、Output レポートを HID デバイスに送信します。

各レポート形式用にデバイスがサポートしている reportId は、HIDDevice.collections から取得できます。

構文

js
sendReport(reportId, data)

引数

reportId

8 ビットのレポート ID です。HID デバイスがレポート ID を使わない場合、0 を送信します。

data

ArrayBuffer, TypedArray, DataView のいずれかで表されるバイト列です。

返値

レポートの送信完了後 undefined で解決する Promise を返します。

例外

NotAllowedError DOMException

何らかの理由でレポートの送信に失敗したとき投げられます。

この例は、Output レポートを用いて Joy-Con デバイスを鳴らす方法を示します。記事 Connecting to uncommon HID devices で他の例や動くデモを見ることができます。

js
// まず、振動を有効化するコマンドを送信します。
// 魔法のバイト列の出典は https://github.com/mzyy94/joycon-toolweb です。
const enableVibrationData = [1, 0, 1, 64, 64, 0, 1, 64, 64, 0x48, 0x01];
await device.sendReport(0x01, new Uint8Array(enableVibrationData));

// 次に、Joy-Con デバイスを鳴らすコマンドを送信します。
// 実際のバイト列はサンプル中にあります。
const rumbleData = [
  /* … */
];
await device.sendReport(0x10, new Uint8Array(rumbleData));

仕様書

Specification
WebHID API
# dom-hiddevice-sendreport

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
sendReport
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.