fix(ice): fix lost ice candidates, close
reorder the function calls to register callbacks before calling set answer
@@ -80,17 +80,6 @@ func (p *Peer) Join(sid string, sdp webrtc.SessionDescription) (*webrtc.SessionD
return nil, fmt.Errorf("error creating transport: %v", err)
}
- p.session.AddPeer(p)
-
- log.Infof("peer %s join session %s", p.id, sid)
-
- answer, err := p.publisher.Answer(sdp)
- if err != nil {
- return nil, fmt.Errorf("error setting remote description: %v", err)
- }
-
- log.Infof("peer %s send answer", p.id)
-
p.subscriber.OnNegotiationNeeded(func() {
p.Lock()
defer p.Unlock()
@@ -114,8 +103,6 @@ func (p *Peer) Join(sid string, sdp webrtc.SessionDescription) (*webrtc.SessionD
}
})
- p.session.Subscribe(p)
-
p.subscriber.OnICECandidate(func(c *webrtc.ICECandidate) {
log.Debugf("on ice candidate called")
if c == nil {
@@ -146,6 +133,19 @@ func (p *Peer) Join(sid string, sdp webrtc.SessionDescription) (*webrtc.SessionD
}
})
+ p.session.AddPeer(p)
+
+ log.Infof("peer %s join session %s", p.id, sid)
+
+ answer, err := p.publisher.Answer(sdp)
+ if err != nil {
+ return nil, fmt.Errorf("error setting remote description: %v", err)
+ }
+
+ log.Infof("peer %s send answer", p.id)
+
+ p.session.Subscribe(p)
+
return &answer, nil
}
