Skip to content

Commit

Permalink
fix: unbind handlers on close (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev authored Jan 21, 2021
1 parent eea2a83 commit f0d71e9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ vendor
*.pem
bin
*.generated.go
.stignore
okteto.yml
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
Expand Down
7 changes: 7 additions & 0 deletions pkg/sfu/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ func (p *Peer) Trickle(candidate webrtc.ICECandidateInit, target int) error {

// Close shuts down the peer connection and sends true to the done channel
func (p *Peer) Close() error {
p.Lock()
defer p.Unlock()

p.OnOffer = nil
p.OnIceCandidate = nil
p.OnICEConnectionStateChange = nil

if p.session != nil {
p.session.RemovePeer(p.id)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/sfu/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ func (r *router) addDownTrack(sub *Subscriber, recv Receiver) error {
downTrack.OnCloseHandler(func() {
if sub.pc.ConnectionState() != webrtc.PeerConnectionStateClosed {
if err := sub.pc.RemoveTrack(downTrack.transceiver.Sender()); err != nil {
if err == webrtc.ErrConnectionClosed {
return
}
log.Errorf("Error closing down track: %v", err)
} else {
sub.RemoveDownTrack(recv.StreamID(), downTrack)
Expand Down

0 comments on commit f0d71e9

Please sign in to comment.