Skip to content

Instantly share code, notes, and snippets.

@sandeep1995
Created April 2, 2025 16:12
Show Gist options
  • Save sandeep1995/ceabe4e7cd735fcf232db9707ec2399d to your computer and use it in GitHub Desktop.
Save sandeep1995/ceabe4e7cd735fcf232db9707ec2399d to your computer and use it in GitHub Desktop.
Fetch media devices
navigator.mediaDevices.getUserMedia({ audio: true, video: true })
.then(stream => {
// Close all tracks after getting permission
stream.getTracks().forEach(track => track.stop());
// Now enumerate devices
return navigator.mediaDevices.enumerateDevices();
})
.then(devices => {
devices.forEach(device => {
console.log(`${device.kind}: ${device.label} (id: ${device.deviceId})`);
});
})
.catch(error => {
console.error('Error:', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment