I'm building an audio chat web application using WebRTC. So I trying to build that if any external audio device get plugged-in to the system my application automatically start using that microphone and when that external device plugged out application start using system default microphone (as Hangout do).<ol><li>
Is there any event that notify me about device plugged-in plugged-out information?(For chrome browser)</li> <li>
Is there any way to know which device to use in all the listed device that we get from browser so that we actually get an audio? (For example as in desktop systems there are two microphone jacks one in front-side another in back-side so when get Media Devices in browser we will get both jacks as device, but how to choose between both jacks that in this particular jack a microphone is plugged-in)</li> <li>
How system choose default device. Is it good to use always default device?</li> <li>
What is the difference between default and communication devices that browser provides?</li> </ol>Answer1:
(1) in the <a href="https://w3c.github.io/mediacapture-main/#event-summary" rel="nofollow">spec</a>, a devicechange event is fired on the navigator.mediaDevices object. That is not yet implemented in Chrome. You can poll navigator.mediaDevices.enumerateDevices which has a performance impact however.
(2) enumerate the devices and look at their labels? See <a href="https://webrtc.github.io/samples/src/content/devices/input-output/" rel="nofollow">this sample</a>