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,
|
echoCancellation: true,
|
||||||
noiseSuppression: true,
|
noiseSuppression: true,
|
||||||
autoGainControl: true,
|
autoGainControl: true,
|
||||||
channelCount: 2,
|
channelCount: 1,
|
||||||
}
|
}
|
||||||
}).then((stream) => {
|
}).then((stream) => {
|
||||||
microphoneRequestInProgress.current = false;
|
microphoneRequestInProgress.current = false;
|
||||||
|
|
@ -652,6 +652,13 @@ export default function KvmIdRoute() {
|
||||||
audioTransceiver.sender.replaceTrack(null);
|
audioTransceiver.sender.replaceTrack(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup on unmount or when dependencies change
|
||||||
|
return () => {
|
||||||
|
if (audioTransceiver?.sender.track) {
|
||||||
|
audioTransceiver.sender.track.stop();
|
||||||
|
}
|
||||||
|
};
|
||||||
}, [microphoneEnabled, audioTransceiver, peerConnection, setMicrophoneEnabled]);
|
}, [microphoneEnabled, audioTransceiver, peerConnection, setMicrophoneEnabled]);
|
||||||
|
|
||||||
// Cleanup effect
|
// Cleanup effect
|
||||||
|
|
|
||||||
|
|
@ -332,6 +332,7 @@ func newSession(config SessionConfig) (*Session, error) {
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
scopedLogger.Warn().Err(err).Msg("Failed to create AudioTrack (non-fatal)")
|
scopedLogger.Warn().Err(err).Msg("Failed to create AudioTrack (non-fatal)")
|
||||||
|
session.AudioTrack = nil
|
||||||
} else {
|
} else {
|
||||||
_, err = peerConnection.AddTransceiverFromTrack(session.AudioTrack, webrtc.RTPTransceiverInit{
|
_, err = peerConnection.AddTransceiverFromTrack(session.AudioTrack, webrtc.RTPTransceiverInit{
|
||||||
Direction: webrtc.RTPTransceiverDirectionSendrecv,
|
Direction: webrtc.RTPTransceiverDirectionSendrecv,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue