How I can know if I have headphones connected to my computer? My goal is to get it using HTML5 + JavaScript.
On the next page shows all audio output devices, but there i
As of today (2019 march) there is no realiable, cross-browser built-in tool to detect whether a user has headphones plugged in. While you theoretically can get audio output destination device and test it for phrases like headset
, earphones
etc, in a typical case it rather provides you with driver's name, which usually doesn't change when user plugs his earphones in. The usually part makes this approach useless.
There is no way using any existing API, but one way could be to send a sound out while checking if the microphone picks it up.
This would be a real test for echo, you could use some "welcome" sound and some FFT code to "parse" microphone input and see if the sound you are sending is re-entering the microphone. However it would require quite some fine tuning to be reliable, and will still not catch people with low volume on the speakers or catch people with too loud headphones .. even if, in that case, since they are producing echo, catching them is probably the right thing to do.
I can't remember which conferencing software was actually doing this setup step emitting a melody and checking the feedback (maybe it was Skype early versions?), but it's doable in modern browsers.