How to use JavaScript to switch between phone speaker and handset

problem description

recently, when developing webrtc, there was a need for customers to switch speakers and handsets on the web page

related codes

found a lot of information on the Internet
navigator.mediaDevices.enumerateDevices (). Then (gotDevices)
function gotDevices (mediaDevices) {

    mediaDevices.forEach((mediaDevice) => {
        if (mediaDevice.kind === "audioinput") {

        }
    });
}

I got the audio output device in this way, but in fact, I only got one or only one device with an id of default.
is there something wrong with my writing method? If I can find more devices, how can I call the new device?

May.05,2022

https://github.com/webrtc/sam...
has found demo, which can be realized by testing, but it seems that some models do not support it. Self-test

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35f00-3439e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35f00-3439e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?