Fix WebRTC send candidates before send answer
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/AlexxIT/go2rtc/cmd/api"
|
"github.com/AlexxIT/go2rtc/cmd/api"
|
||||||
"github.com/AlexxIT/go2rtc/cmd/app"
|
"github.com/AlexxIT/go2rtc/cmd/app"
|
||||||
"github.com/AlexxIT/go2rtc/cmd/streams"
|
"github.com/AlexxIT/go2rtc/cmd/streams"
|
||||||
|
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/webrtc"
|
"github.com/AlexxIT/go2rtc/pkg/webrtc"
|
||||||
pion "github.com/pion/webrtc/v3"
|
pion "github.com/pion/webrtc/v3"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
@@ -98,6 +99,8 @@ func asyncHandler(tr *api.Transport, msg *api.Message) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sendAnswer core.Waiter
|
||||||
|
|
||||||
cons := webrtc.NewConn(pc)
|
cons := webrtc.NewConn(pc)
|
||||||
cons.UserAgent = tr.Request.UserAgent()
|
cons.UserAgent = tr.Request.UserAgent()
|
||||||
cons.Listen(func(msg any) {
|
cons.Listen(func(msg any) {
|
||||||
@@ -106,13 +109,18 @@ func asyncHandler(tr *api.Transport, msg *api.Message) error {
|
|||||||
if msg == pion.PeerConnectionStateClosed {
|
if msg == pion.PeerConnectionStateClosed {
|
||||||
stream.RemoveConsumer(cons)
|
stream.RemoveConsumer(cons)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *pion.ICECandidate:
|
case *pion.ICECandidate:
|
||||||
if msg != nil {
|
if msg == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sendAnswer.Wait()
|
||||||
|
|
||||||
s := msg.ToJSON().Candidate
|
s := msg.ToJSON().Candidate
|
||||||
log.Trace().Str("candidate", s).Msg("[webrtc] local")
|
log.Trace().Str("candidate", s).Msg("[webrtc] local")
|
||||||
tr.Write(&api.Message{Type: "webrtc/candidate", Value: s})
|
tr.Write(&api.Message{Type: "webrtc/candidate", Value: s})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// V2 - json/object exchange, V1 - raw SDP exchange
|
// V2 - json/object exchange, V1 - raw SDP exchange
|
||||||
@@ -156,6 +164,8 @@ func asyncHandler(tr *api.Transport, msg *api.Message) error {
|
|||||||
tr.Write(&api.Message{Type: "webrtc/answer", Value: answer})
|
tr.Write(&api.Message{Type: "webrtc/answer", Value: answer})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendAnswer.Done()
|
||||||
|
|
||||||
asyncCandidates(tr, cons)
|
asyncCandidates(tr, cons)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
Reference in New Issue
Block a user