Update go2rtc candidates processing

This commit is contained in:
Alexey Khit
2023-03-04 06:25:30 +03:00
parent d805d560b9
commit 9ab9412c95
7 changed files with 49 additions and 28 deletions
+2 -11
View File
@@ -48,8 +48,8 @@ func GetCandidates() (candidates []string) {
candidates = append(
candidates,
webrtc.CandidateHostUDP(address.Host, address.Port),
webrtc.CandidateHostTCPPassive(address.Host, address.Port),
webrtc.CandidateManualHostUDP(address.Host, address.Port),
webrtc.CandidateManualHostTCPPassive(address.Host, address.Port),
)
}
@@ -90,19 +90,10 @@ func syncCanditates(answer string) (string, error) {
md := sd.MediaDescriptions[0]
_, end := md.Attribute("end-of-candidates")
if end {
md.Attributes = md.Attributes[:len(md.Attributes)-1]
}
for _, candidate := range GetCandidates() {
md.WithPropertyAttribute(candidate)
}
if end {
md.WithPropertyAttribute("end-of-candidates")
}
data, err := sd.Marshal()
if err != nil {
return "", err
+10 -5
View File
@@ -3,6 +3,7 @@ package webrtc
import (
"errors"
"github.com/AlexxIT/go2rtc/cmd/api"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/streamer"
"github.com/AlexxIT/go2rtc/pkg/webrtc"
"github.com/gorilla/websocket"
@@ -45,6 +46,8 @@ func asyncClient(url string) (streamer.Producer, error) {
return nil, err
}
var sendOffer core.Waiter
prod := webrtc.NewConn(pc)
prod.Listen(func(msg any) {
switch msg := msg.(type) {
@@ -52,11 +55,11 @@ func asyncClient(url string) (streamer.Producer, error) {
_ = ws.Close()
case *pion.ICECandidate:
if msg != nil {
s := msg.ToJSON().Candidate
log.Trace().Str("candidate", s).Msg("[webrtc] local")
_ = ws.WriteJSON(&api.Message{Type: "webrtc/candidate", Value: s})
}
sendOffer.Wait()
s := msg.ToJSON().Candidate
log.Trace().Str("candidate", s).Msg("[webrtc] local")
_ = ws.WriteJSON(&api.Message{Type: "webrtc/candidate", Value: s})
}
})
@@ -77,6 +80,8 @@ func asyncClient(url string) (streamer.Producer, error) {
return nil, err
}
sendOffer.Done()
// 5. Get answer
if err = ws.ReadJSON(msg); err != nil {
return nil, err
-4
View File
@@ -111,10 +111,6 @@ func asyncHandler(tr *api.Transport, msg *api.Message) error {
}
case *pion.ICECandidate:
if msg == nil {
return
}
sendAnswer.Wait()
s := msg.ToJSON().Candidate