MediaDeviceInfo: toJSON() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.
MediaDeviceInfo
インターフェイスの toJSON()
メソッドは、シリアライザーです。このメソッドは、この MediaDeviceInfo
オブジェクトの JSON 表現を返します。
構文
js
toJSON()
引数
なし
返値
この MediaDeviceInfo
オブジェクトをシリアライズした JSON
オブジェクトを返します。
例
js
if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
console.log("enumerateDevices() に未対応です。");
} else {
// カメラとマイクを列挙する
navigator.mediaDevices
.enumerateDevices()
.then((devices) => {
devices.forEach((device) => {
console.log(device.toJSON());
});
})
.catch((err) => {
console.log(`${err.name}: ${err.message}`);
});
}
以下の結果になる可能性があります。
bash
Object { deviceId: "HJtTemQTM64Bivxv3ZEyKjCi1VR8042lPNpmXKObKJE=", kind: "videoinput", label: "", groupId: "Okm2l1YZTrwy8awTxE8QSLNFoVMdIXx++wLh68tbmv0=" }
Object { deviceId: "EqDubLxPlPeW+5w/ereWTF/3EaAMVHh9QBBHkZHiP0k=", kind: "audioinput", label: "", groupId: "Okm2l1YZTrwy8awTxE8QSLNFoVMdIXx++wLh68tbmv0=" }
Object { deviceId: "CanWttL2RnHOiS7FzzYXMIvLqVFE5S06Lfy8H//nhEw=", kind: "audioinput", label: "", groupId: "nOdLNeXGIw9oL9f2wH69SssQpRVs7cmt9jqZrUWgQwI=" }
仕様書
Specification |
---|
Media Capture and Streams # dom-mediadeviceinfo-tojson |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
toJSON() |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.