From 20448ec6a8da6b96bb7c51a0378232965537fb3a Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 8 Jan 2023 19:18:13 +0100 Subject: [PATCH] webrtc muxer: fix sending local candidates --- internal/core/webrtc_conn.go | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/internal/core/webrtc_conn.go b/internal/core/webrtc_conn.go index 68e455c0..b3da7711 100644 --- a/internal/core/webrtc_conn.go +++ b/internal/core/webrtc_conn.go @@ -311,7 +311,7 @@ func (c *webRTCConn) runInner(ctx context.Context) error { return err } - err = c.writeICEServers(c.genICEServers()) + err = c.wsconn.WriteJSON(c.genICEServers()) if err != nil { return err } @@ -390,12 +390,13 @@ func (c *webRTCConn) runInner(ctx context.Context) error { }() } - localCandidate := make(chan *webrtc.ICECandidate) + localCandidate := make(chan *webrtc.ICECandidateInit) pc.OnICECandidate(func(i *webrtc.ICECandidate) { if i != nil { + v := i.ToJSON() select { - case localCandidate <- i: + case localCandidate <- &v: case <-pcConnected: case <-ctx.Done(): } @@ -416,7 +417,7 @@ func (c *webRTCConn) runInner(ctx context.Context) error { return err } - err = c.writeAnswer(&answer) + err = c.wsconn.WriteJSON(&answer) if err != nil { return err } @@ -450,12 +451,15 @@ outer: for { select { case candidate := <-localCandidate: - c.log(logger.Debug, "local candidate: %+v", candidate) - c.writeCandidate(candidate) + c.log(logger.Debug, "local candidate: %+v", candidate.Candidate) + err := c.wsconn.WriteJSON(candidate) + if err != nil { + return err + } case candidate := <-remoteCandidate: c.log(logger.Debug, "remote candidate: %+v", candidate.Candidate) - err = pc.AddICECandidate(*candidate) + err := pc.AddICECandidate(*candidate) if err != nil { return err } @@ -838,10 +842,6 @@ func (c *webRTCConn) genICEServers() []webrtc.ICEServer { return ret } -func (c *webRTCConn) writeICEServers(iceServers []webrtc.ICEServer) error { - return c.wsconn.WriteJSON(iceServers) -} - func (c *webRTCConn) readOffer() (*webrtc.SessionDescription, error) { var offer webrtc.SessionDescription err := c.wsconn.ReadJSON(&offer) @@ -856,14 +856,6 @@ func (c *webRTCConn) readOffer() (*webrtc.SessionDescription, error) { return &offer, nil } -func (c *webRTCConn) writeAnswer(answer *webrtc.SessionDescription) error { - return c.wsconn.WriteJSON(answer) -} - -func (c *webRTCConn) writeCandidate(candidate *webrtc.ICECandidate) error { - return c.wsconn.WriteJSON(candidate) -} - func (c *webRTCConn) readCandidate() (*webrtc.ICECandidateInit, error) { var candidate webrtc.ICECandidateInit err := c.wsconn.ReadJSON(&candidate)