mirror of
https://github.com/coder/coder.git
synced 2025-04-14 17:21:03 +00:00
fix: ensure rtc state changes can't log after close (#1213)
This commit is contained in:
16
peer/conn.go
16
peer/conn.go
@ -221,19 +221,35 @@ func (c *Conn) init() error {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// These functions need to check if the conn is closed, because they can be
|
||||
// called after being closed.
|
||||
c.rtc.OnSignalingStateChange(func(signalState webrtc.SignalingState) {
|
||||
if c.isClosed() {
|
||||
return
|
||||
}
|
||||
c.opts.Logger.Debug(context.Background(), "signaling state updated",
|
||||
slog.F("state", signalState))
|
||||
})
|
||||
c.rtc.SCTP().Transport().OnStateChange(func(dtlsTransportState webrtc.DTLSTransportState) {
|
||||
if c.isClosed() {
|
||||
return
|
||||
}
|
||||
c.opts.Logger.Debug(context.Background(), "dtls transport state updated",
|
||||
slog.F("state", dtlsTransportState))
|
||||
})
|
||||
c.rtc.SCTP().Transport().ICETransport().OnSelectedCandidatePairChange(func(candidatePair *webrtc.ICECandidatePair) {
|
||||
if c.isClosed() {
|
||||
return
|
||||
}
|
||||
c.opts.Logger.Debug(context.Background(), "selected candidate pair changed",
|
||||
slog.F("local", candidatePair.Local), slog.F("remote", candidatePair.Remote))
|
||||
})
|
||||
c.rtc.OnICECandidate(func(iceCandidate *webrtc.ICECandidate) {
|
||||
if c.isClosed() {
|
||||
return
|
||||
}
|
||||
|
||||
if iceCandidate == nil {
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user