don't set PeerConnection callbacks, ignore the responses instead

This commit is contained in:
David Zhao
2021-06-17 22:54:09 -07:00
parent e527a66096
commit b2201a7b34
+10 -6
View File
@@ -114,13 +114,13 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
} }
p.publisher.pc.OnICECandidate(func(c *webrtc.ICECandidate) { p.publisher.pc.OnICECandidate(func(c *webrtc.ICECandidate) {
if c == nil { if c == nil || p.State() == livekit.ParticipantInfo_DISCONNECTED {
return return
} }
p.sendIceCandidate(c, livekit.SignalTarget_PUBLISHER) p.sendIceCandidate(c, livekit.SignalTarget_PUBLISHER)
}) })
p.subscriber.pc.OnICECandidate(func(c *webrtc.ICECandidate) { p.subscriber.pc.OnICECandidate(func(c *webrtc.ICECandidate) {
if c == nil { if c == nil || p.State() == livekit.ParticipantInfo_DISCONNECTED {
return return
} }
p.sendIceCandidate(c, livekit.SignalTarget_SUBSCRIBER) p.sendIceCandidate(c, livekit.SignalTarget_SUBSCRIBER)
@@ -381,10 +381,7 @@ func (p *ParticipantImpl) Close() error {
} }
p.updateState(livekit.ParticipantInfo_DISCONNECTED) p.updateState(livekit.ParticipantInfo_DISCONNECTED)
p.subscriber.pc.OnDataChannel(nil)
p.subscriber.pc.OnICECandidate(nil)
p.subscriber.pc.OnTrack(nil)
p.publisher.pc.OnICECandidate(nil)
// ensure this is synchronized // ensure this is synchronized
p.lock.RLock() p.lock.RLock()
p.params.Sink.Close() p.params.Sink.Close()
@@ -675,6 +672,10 @@ func (p *ParticipantImpl) onOffer(offer webrtc.SessionDescription) {
// when a new remoteTrack is created, creates a Track and adds it to room // when a new remoteTrack is created, creates a Track and adds it to room
func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *webrtc.RTPReceiver) { func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *webrtc.RTPReceiver) {
if p.State() == livekit.ParticipantInfo_DISCONNECTED {
return
}
logger.Debugw("mediaTrack added", logger.Debugw("mediaTrack added",
"participant", p.Identity(), "participant", p.Identity(),
"remoteTrack", track.ID(), "remoteTrack", track.ID(),
@@ -729,6 +730,9 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w
} }
func (p *ParticipantImpl) onDataChannel(dc *webrtc.DataChannel) { func (p *ParticipantImpl) onDataChannel(dc *webrtc.DataChannel) {
if p.State() == livekit.ParticipantInfo_DISCONNECTED {
return
}
switch dc.Label() { switch dc.Label() {
case reliableDataChannel: case reliableDataChannel:
p.reliableDC = dc p.reliableDC = dc