replaceTracks leaves previous audio input open in my application, but Device Selection demo works OK

I have an audio room application where the user can switch the mic input.

When I switch the sound input to the audio room using the replaceTracks function of the API then I can see the both the previous and new audio devices in Pulse Audio as being used by the browser for “recording”.

However, if I switch audio devices in the Device Selection demo, the audio input that the browser is “recording” simply changes in place. Not duplicates.
https://janus.conf.meetecho.com/devicetest.html

I can’t find anything that I am forgetting to do that would result in the sound input hanging. The application still works, in that it uses the last selected audio input, but this is obviously a bit messy.

How do I cleanly switch sound inputs without leaving the previous one active?

       gSendMixerHandle.replaceTracks({
            tracks: [
                        { type: 'audio',
                            mid: '0',
                            capture: {
                                autoGainControl: true,
                                latency: 0,
                                echoCancellation: !gMusicTx,
                                noiseSuppression: !gMusicTx,
                                deviceId: {
                                    exact: micDeviceId
                                }
                            },
                            recv: true
                        }
                    ],
            error: function(err) {
                Janus.error("Error when changing Mic : ", err);
            }
        });

If our demo is working fine, and you’re not using janus.js in your application, check where we do the replaceTrack stuff in janus.js. It’s likely we get rid of old tracks somehow, which is why you probably don’t see the duplicates there.

I am using janus.js.

I just discovered that if I use the very latest version of janus.js from Github instead of the one that comes with the 23.04 and even 23.10 Ubuntu distribution then it fixes the problem.

It seems that this was probably a bug in janus.js that has recently been fixed.