Created
April 2, 2025 16:12
-
-
Save sandeep1995/ceabe4e7cd735fcf232db9707ec2399d to your computer and use it in GitHub Desktop.
Fetch media devices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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