Namespace: SpawnDev.SpawnJS.JSObjects
Inherits: SpawnJSObject
Source: JSObjects/MediaDeviceInfo.cs
MDN Reference: MediaDeviceInfo on MDN
The MediaDeviceInfo interface of the Media Capture and Streams API contains information that describes a single media input or output device. https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo
| Signature | Description |
|---|---|
MediaDeviceInfo(SpawnJSObjectReference _ref) |
Deserialization constructor |
| Property | Type | Access | Description |
|---|---|---|---|
DeviceId |
string |
get | Returns a string that is an identifier for the represented device that is persisted across sessions. It is un-guessable by other applications and unique to the origin of the calling application. It is reset when the user clears cookies (for Private Browsing, a different identifier is used that is not persisted across sessions). |
Kind |
string |
get | Returns an enumerated value that is either "videoinput", "audioinput" or "audiooutput". |
Label |
string |
get | Returns a string describing this device (for example "External USB Webcam"). Note: For security reasons, the label field is always blank unless an active media stream exists or the user has granted persistent permission for media device access. The set of device labels could otherwise be used as part of a fingerprinting mechanism to identify a user. |
GroupId |
string |
get | Returns a string that is a group identifier. Two devices have the same group identifier if they belong to the same physical device - for example a monitor with both a built-in camera and a microphone. |
Facing |
EnumString<VideoFacingModeEnum>? |
get | Facing mode |
| Method | Return Type | Description |
|---|---|---|
ToJSON() |
MediaDeviceInfoJson |
Returns a JSON representation of the MediaDeviceInfo object. |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<MediaDeviceInfo>(...)or constructornew MediaDeviceInfo(...)
if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
console.log("enumerateDevices() not supported.");
} else {
// List cameras and microphones.
navigator.mediaDevices
.enumerateDevices()
.then((devices) => {
devices.forEach((device) => {
console.log(`${device.kind}: ${device.label} id = ${device.deviceId}`);
});
})
.catch((err) => {
console.log(`${err.name}: ${err.message}`);
});
}