Code refactoring for webrtc candidates

This commit is contained in:
Alexey Khit
2022-12-01 23:41:12 +03:00
parent 8c6729027b
commit 999e81c2dd
4 changed files with 17 additions and 31 deletions
+1 -12
View File
@@ -5,13 +5,6 @@ import (
"github.com/pion/webrtc/v3"
)
const (
MsgTypeOffer = "webrtc/offer"
MsgTypeOfferComplete = "webrtc/offer-complete"
MsgTypeAnswer = "webrtc/answer"
MsgTypeCandidate = "webrtc/candidate"
)
type Conn struct {
streamer.Element
@@ -28,11 +21,7 @@ type Conn struct {
func (c *Conn) Init() {
c.Conn.OnICECandidate(func(candidate *webrtc.ICECandidate) {
if candidate != nil {
c.Fire(&streamer.Message{
Type: MsgTypeCandidate, Value: candidate.ToJSON().Candidate,
})
}
c.Fire(candidate)
})
c.Conn.OnTrack(func(remote *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
+2 -8
View File
@@ -108,14 +108,8 @@ func (c *Conn) AddTrack(media *streamer.Media, track *streamer.Track) *streamer.
//
func (c *Conn) Push(msg interface{}) {
if msg := msg.(*streamer.Message); msg != nil {
if msg.Type == MsgTypeCandidate {
_ = c.Conn.AddICECandidate(webrtc.ICECandidateInit{
Candidate: msg.Value.(string),
})
}
}
func (c *Conn) AddCandidate(candidate string) {
_ = c.Conn.AddICECandidate(webrtc.ICECandidateInit{Candidate: candidate})
}
func (c *Conn) MarshalJSON() ([]byte, error) {