@@ -145,39 +145,39 @@ func (c *Conn) init() error {
145
145
146
146
c .rtc .OnNegotiationNeeded (c .negotiate )
147
147
c .rtc .OnICEConnectionStateChange (func (iceConnectionState webrtc.ICEConnectionState ) {
148
- if c .isClosed () {
148
+ c .closedICEMutex .Lock ()
149
+ defer c .closedICEMutex .Unlock ()
150
+ select {
151
+ case <- c .closedICE :
152
+ // Don't log more state changes if we've already closed.
149
153
return
150
- }
151
-
152
- c .opts .Logger .Debug (context .Background (), "ice connection state updated" ,
153
- slog .F ("state" , iceConnectionState ))
154
+ default :
155
+ c .opts .Logger .Debug (context .Background (), "ice connection state updated" ,
156
+ slog .F ("state" , iceConnectionState ))
154
157
155
- if iceConnectionState == webrtc .ICEConnectionStateClosed {
156
- // pion/webrtc can update this state multiple times.
157
- // A connection can never become un-closed, so we
158
- // close the channel if it isn't already.
159
- c .closedICEMutex .Lock ()
160
- defer c .closedICEMutex .Unlock ()
161
- select {
162
- case <- c .closedICE :
163
- default :
158
+ if iceConnectionState == webrtc .ICEConnectionStateClosed {
159
+ // pion/webrtc can update this state multiple times.
160
+ // A connection can never become un-closed, so we
161
+ // close the channel if it isn't already.
164
162
close (c .closedICE )
165
163
}
166
164
}
167
165
})
168
166
c .rtc .OnICEGatheringStateChange (func (iceGatherState webrtc.ICEGathererState ) {
169
- c .opts .Logger .Debug (context .Background (), "ice gathering state updated" ,
170
- slog .F ("state" , iceGatherState ))
167
+ c .closedICEMutex .Lock ()
168
+ defer c .closedICEMutex .Unlock ()
169
+ select {
170
+ case <- c .closedICE :
171
+ // Don't log more state changes if we've already closed.
172
+ return
173
+ default :
174
+ c .opts .Logger .Debug (context .Background (), "ice gathering state updated" ,
175
+ slog .F ("state" , iceGatherState ))
171
176
172
- if iceGatherState == webrtc .ICEGathererStateClosed {
173
- // pion/webrtc can update this state multiple times.
174
- // A connection can never become un-closed, so we
175
- // close the channel if it isn't already.
176
- c .closedICEMutex .Lock ()
177
- defer c .closedICEMutex .Unlock ()
178
- select {
179
- case <- c .closedICE :
180
- default :
177
+ if iceGatherState == webrtc .ICEGathererStateClosed {
178
+ // pion/webrtc can update this state multiple times.
179
+ // A connection can never become un-closed, so we
180
+ // close the channel if it isn't already.
181
181
close (c .closedICE )
182
182
}
183
183
}
@@ -292,7 +292,7 @@ func (c *Conn) negotiate() {
292
292
_ = c .CloseWithError (xerrors .Errorf ("set local description: %w" , err ))
293
293
return
294
294
}
295
- c .opts .Logger .Debug (context .Background (), "sending offer" )
295
+ c .opts .Logger .Debug (context .Background (), "sending offer" , slog . F ( "offer" , offer ) )
296
296
select {
297
297
case <- c .closed :
298
298
return
@@ -331,7 +331,7 @@ func (c *Conn) negotiate() {
331
331
_ = c .CloseWithError (xerrors .Errorf ("set local description: %w" , err ))
332
332
return
333
333
}
334
- c .opts .Logger .Debug (context .Background (), "sending answer" )
334
+ c .opts .Logger .Debug (context .Background (), "sending answer" , slog . F ( "answer" , answer ) )
335
335
select {
336
336
case <- c .closed :
337
337
return
0 commit comments