mirror of
https://github.com/jetkvm/kvm.git
synced 2026-05-21 05:20:35 +00:00
Fix onSessionConnected race; replace onFirst/CurrentSessionConnected split
The previous codex split routed audio start through onCurrentSessionConnected, gated on session == currentSession. But currentSession is assigned by the caller (web.go, cloud.go) AFTER ExchangeOffer returns, while OnICEConnectionStateChange can fire from inside ExchangeOffer or shortly after — racing the assignment. When the race hits, the equality check fails, the callback is skipped, and audio never starts. Pass session into the callback directly so the per-session setup uses the session in hand, not whatever currentSession happens to point to at that instant. Keep stopVideoSleepModeTicker on the count-edge (still only on first-session) and let onSessionConnected handle the rest unconditionally.
This commit is contained in:
@@ -552,11 +552,9 @@ func newSession(config SessionConfig) (*Session, error) {
|
||||
isConnected = true
|
||||
onActiveSessionsChanged()
|
||||
if incrActiveSessions() == 1 {
|
||||
onFirstSessionConnected()
|
||||
}
|
||||
if session == currentSession {
|
||||
onCurrentSessionConnected(session)
|
||||
stopVideoSleepModeTicker()
|
||||
}
|
||||
onSessionConnected(session)
|
||||
if mqttManager != nil {
|
||||
mqttManager.publishSessionsState()
|
||||
}
|
||||
@@ -609,24 +607,19 @@ func onActiveSessionsChanged() {
|
||||
requestDisplayUpdate(false, "active_sessions_changed")
|
||||
}
|
||||
|
||||
func onFirstSessionConnected() {
|
||||
stopVideoSleepModeTicker()
|
||||
}
|
||||
|
||||
func onCurrentSessionConnected(session *Session) {
|
||||
// onSessionConnected runs per session when ICE reaches Connected. Uses the
|
||||
// session parameter directly rather than the currentSession global — that
|
||||
// global is assigned by the caller AFTER ExchangeOffer returns, and ICE
|
||||
// connected can fire before then, racing the assignment.
|
||||
func onSessionConnected(session *Session) {
|
||||
notifyFailsafeMode(session)
|
||||
if session != nil && session.codecMimeType == webrtc.MimeTypeH265 {
|
||||
if session.codecMimeType == webrtc.MimeTypeH265 {
|
||||
_ = nativeInstance.VideoSetCodecType(1)
|
||||
} else {
|
||||
_ = nativeInstance.VideoSetCodecType(0)
|
||||
}
|
||||
_ = nativeInstance.VideoStart()
|
||||
|
||||
var audioTrack *webrtc.TrackLocalStaticSample
|
||||
if session != nil {
|
||||
audioTrack = session.AudioTrack
|
||||
}
|
||||
startAudio(audioTrack)
|
||||
startAudio(session.AudioTrack)
|
||||
}
|
||||
|
||||
func onLastSessionDisconnected() {
|
||||
|
||||
Reference in New Issue
Block a user