diff --git a/devices.css b/devices.css new file mode 100644 index 0000000..6fb0383 --- /dev/null +++ b/devices.css @@ -0,0 +1,62 @@ +#devices { + max-width: 80%; + width: fit-content; + margin: 0 auto; +} + +h1 { + font-size: 1.5em; + padding:10px; + background-color:#457b9d; + color:white; +} + +.device { + display: flex; + flex-direction: column; + margin: 20px 0px; + font-size: 1rem; +} + +.device-name{ + font-weight: bold; + margin-bottom: 5px; +} + +.device-id { + +} + +.card { + margin: 10px; +} + +.card > div { + padding: 10px; +} + +.notice { + background-color: orange; + margin: 10px; + padding: 20px 20px; + font-weight: bold; + font-size: 1.2em; + text-align: center; +} + +.notice a { + color: #457b9d; +} + +@media only screen + and (min-device-width: 375px) + and (max-device-width: 812px) + and (orientation: portrait) { + #devices { + width: 100%; + } + .device-id { + text-overflow: ellipsis; + overflow: hidden; + } +} \ No newline at end of file diff --git a/devices.html b/devices.html index 8474054..e5fcff8 100644 --- a/devices.html +++ b/devices.html @@ -1,28 +1,94 @@ - + + + + + + + -
- - - \ No newline at end of file + function isAudioInput(value) { + return value.kind == "audioinput"; + } + + function isAudioOutput(value) { + return value.kind == "audiooutput"; + } + + function isVideoInput(value) { + return value.kind == "videoinput"; + } + + function prettyPrint(json, element) { + var output = "
"; + + var nestedObjs; + + Object.entries(json) + .sort() + .forEach(([key, value]) => { + output += "
"; + + output += + "" + + value.label + + "Device ID: " + + value.deviceId + + ""; + + output += "
"; + }); + output += "
"; + document.getElementById(element).innerHTML = output; + } + + navigator.mediaDevices + .enumerateDevices() + .then(function (devices) { + devices.forEach(function (device) { + console.log( + device.kind + ": " + device.label + " id = " + device.deviceId + ); + list.push(device); + }); + prettyPrint(devices.filter(isAudioInput), "audioInputs"); + prettyPrint(devices.filter(isAudioOutput), "audioOutputs"); + prettyPrint(devices.filter(isVideoInput), "videoInputs"); + }) + .catch(function (err) { + console.log(err.name + ": " + err.message); + }); + + +