Skip to content

Commit

Permalink
Close interceptor after PeerConnection is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
aalekseevx committed Dec 24, 2024
1 parent b82306a commit f36bb3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ func Test_Interceptor_BindUnbind(t *testing.T) {
}
}()

closePairNow(t, sender, receiver)
assert.NoError(t, sender.GracefulClose())
assert.NoError(t, receiver.GracefulClose())

// Bind/UnbindLocal/RemoteStream should be called from one side.
if cnt := atomic.LoadUint32(&cntBindLocalStream); cnt != 1 {
Expand Down
5 changes: 3 additions & 2 deletions peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2209,8 +2209,6 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error {
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #3)
pc.signalingState.Set(SignalingStateClosed)

closeErrs = append(closeErrs, pc.api.interceptor.Close())

// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #4)
pc.mu.Lock()
for _, t := range pc.rtpTransceivers {
Expand Down Expand Up @@ -2247,6 +2245,9 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error {

closeErrs = append(closeErrs, doGracefulCloseOps()...)

// Interceptor closes at the end to prevent Bind from being called after interceptor is closed
closeErrs = append(closeErrs, pc.api.interceptor.Close())

return util.FlattenErrs(closeErrs)
}

Expand Down

0 comments on commit f36bb3d

Please sign in to comment.