mirror of https://github.com/jetkvm/kvm.git
fix: improve microphone handling and cleanup
- Use mono audio instead of stereo for microphone input - Add cleanup to stop audio track on component unmount - Explicitly set AudioTrack to nil when creation fails
This commit is contained in:
parent
41345b0527
commit
d1824c5727
|
|
@ -620,7 +620,7 @@ export default function KvmIdRoute() {
|
|||
echoCancellation: true,
|
||||
noiseSuppression: true,
|
||||
autoGainControl: true,
|
||||
channelCount: 2,
|
||||
channelCount: 1,
|
||||
}
|
||||
}).then((stream) => {
|
||||
microphoneRequestInProgress.current = false;
|
||||
|
|
@ -652,6 +652,13 @@ export default function KvmIdRoute() {
|
|||
audioTransceiver.sender.replaceTrack(null);
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup on unmount or when dependencies change
|
||||
return () => {
|
||||
if (audioTransceiver?.sender.track) {
|
||||
audioTransceiver.sender.track.stop();
|
||||
}
|
||||
};
|
||||
}, [microphoneEnabled, audioTransceiver, peerConnection, setMicrophoneEnabled]);
|
||||
|
||||
// Cleanup effect
|
||||
|
|
|
|||
|
|
@ -332,6 +332,7 @@ func newSession(config SessionConfig) (*Session, error) {
|
|||
)
|
||||
if err != nil {
|
||||
scopedLogger.Warn().Err(err).Msg("Failed to create AudioTrack (non-fatal)")
|
||||
session.AudioTrack = nil
|
||||
} else {
|
||||
_, err = peerConnection.AddTransceiverFromTrack(session.AudioTrack, webrtc.RTPTransceiverInit{
|
||||
Direction: webrtc.RTPTransceiverDirectionSendrecv,
|
||||
|
|
|
|||
Loading…
Reference in New Issue