gum device presence fingerprint

by jib1

HTML

<script src="https://webrtchacks.github.io/adapter/adapter-latest.js"></script>
<video id="video" width="160" height="120" autoplay></video><br>
<div id="div"></div>

JavaScript

const console = { log: msg => div.innerHTML += msg + "<br>" };

(async () => {
  try {
    const [{deviceId}] = (await navigator.mediaDevices.enumerateDevices())
      .filter(({kind}) => kind == "videoinput");
    for (const id of [deviceId, `MadeUpId`]) {
      console.log(`${id} is ${await isDevicePresent(id)? "" : "not"} present`);
    }
  } catch(e) {
    console.log(e);
  }
})();

async function isDevicePresent(id) {
  try {
    await navigator.mediaDevices.getUserMedia({video: {
        deviceId: {exact: id}, width: {max: 0}
    }});
  } catch (e) {
    return e.constraint == "width";
  }
}