mirror of https://github.com/jetkvm/kvm.git
Compare commits
2 Commits
6078cdab66
...
d1824c5727
| Author | SHA1 | Date |
|---|---|---|
|
|
d1824c5727 | |
|
|
41345b0527 |
6
Makefile
6
Makefile
|
|
@ -205,14 +205,12 @@ lint-go-fix: build_audio_deps
|
|||
# Run UI linting locally (mirrors GitHub workflow ui-lint.yml)
|
||||
lint-ui:
|
||||
@echo "Running UI lint..."
|
||||
@cd ui && npm ci
|
||||
@cd ui && npm run lint
|
||||
@cd ui && npm ci && npm run lint
|
||||
|
||||
# Run UI linting with auto-fix
|
||||
lint-ui-fix:
|
||||
@echo "Running UI lint with auto-fix..."
|
||||
@cd ui && npm ci
|
||||
@cd ui && npm run lint:fix
|
||||
@cd ui && npm ci && npm run lint:fix
|
||||
|
||||
# Legacy alias for UI linting (for backward compatibility)
|
||||
ui-lint: lint-ui
|
||||
|
|
|
|||
35
audio.go
35
audio.go
|
|
@ -14,7 +14,7 @@ import (
|
|||
var (
|
||||
audioMutex sync.Mutex
|
||||
outputSource audio.AudioSource
|
||||
inputSource audio.AudioSource
|
||||
inputSource atomic.Pointer[audio.AudioSource]
|
||||
outputRelay *audio.OutputRelay
|
||||
inputRelay *audio.InputRelay
|
||||
audioInitialized bool
|
||||
|
|
@ -63,13 +63,15 @@ func startAudio() error {
|
|||
|
||||
// Start input audio if not running, USB audio enabled, and input enabled
|
||||
ensureConfigLoaded()
|
||||
if inputSource == nil && audioInputEnabled.Load() && config.UsbDevices != nil && config.UsbDevices.Audio {
|
||||
if inputSource.Load() == nil && audioInputEnabled.Load() && config.UsbDevices != nil && config.UsbDevices.Audio {
|
||||
alsaPlaybackDevice := "hw:1,0" // USB speakers
|
||||
|
||||
// Create CGO audio source
|
||||
inputSource = audio.NewCgoInputSource(alsaPlaybackDevice)
|
||||
newInputSource := audio.NewCgoInputSource(alsaPlaybackDevice)
|
||||
var audioSrc audio.AudioSource = newInputSource
|
||||
inputSource.Store(&audioSrc)
|
||||
|
||||
inputRelay = audio.NewInputRelay(inputSource)
|
||||
inputRelay = audio.NewInputRelay(newInputSource)
|
||||
if err := inputRelay.Start(); err != nil {
|
||||
audioLogger.Error().Err(err).Msg("Failed to start input relay")
|
||||
}
|
||||
|
|
@ -96,9 +98,9 @@ func stopInputLocked() {
|
|||
inputRelay.Stop()
|
||||
inputRelay = nil
|
||||
}
|
||||
if inputSource != nil {
|
||||
inputSource.Disconnect()
|
||||
inputSource = nil
|
||||
if source := inputSource.Load(); source != nil {
|
||||
(*source).Disconnect()
|
||||
inputSource.Store(nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -169,8 +171,8 @@ func SetAudioOutputEnabled(enabled bool) error {
|
|||
}
|
||||
} else {
|
||||
audioMutex.Lock()
|
||||
defer audioMutex.Unlock()
|
||||
stopOutputLocked()
|
||||
audioMutex.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -188,8 +190,8 @@ func SetAudioInputEnabled(enabled bool) error {
|
|||
}
|
||||
} else {
|
||||
audioMutex.Lock()
|
||||
defer audioMutex.Unlock()
|
||||
stopInputLocked()
|
||||
audioMutex.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -238,23 +240,22 @@ func handleInputTrackForSession(track *webrtc.TrackRemote) {
|
|||
continue // Drop frame but keep reading
|
||||
}
|
||||
|
||||
// Get source in single mutex operation (hot path optimization)
|
||||
audioMutex.Lock()
|
||||
source := inputSource
|
||||
audioMutex.Unlock()
|
||||
// Get source atomically (hot path optimization)
|
||||
source := inputSource.Load()
|
||||
|
||||
if source == nil {
|
||||
continue // No relay, drop frame but keep reading
|
||||
}
|
||||
|
||||
if !source.IsConnected() {
|
||||
if err := source.Connect(); err != nil {
|
||||
if !(*source).IsConnected() {
|
||||
if err := (*source).Connect(); err != nil {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if err := source.WriteMessage(0, opusData); err != nil {
|
||||
source.Disconnect()
|
||||
if err := (*source).WriteMessage(0, opusData); err != nil {
|
||||
(*source).Disconnect()
|
||||
audioLogger.Warn().Err(err).Str("track_id", myTrackID).Msg("failed to write audio message")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
main.go
2
main.go
|
|
@ -133,7 +133,7 @@ func Main() {
|
|||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-sigs
|
||||
|
||||
logger.Info().Msg("JetKVM Shutting Down")
|
||||
logger.Log().Msg("JetKVM Shutting Down")
|
||||
|
||||
stopAudio()
|
||||
|
||||
|
|
|
|||
|
|
@ -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