Skip to content

Commit

Permalink
better code
Browse files Browse the repository at this point in the history
  • Loading branch information
craymond12 committed Sep 6, 2024
1 parent b19499c commit 361fc46
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error {

// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #6)
if pc.sctpTransport != nil {
closeErrs = append(closeErrs, pc.sctpTransport.Stop())
closeErrs = append(closeErrs, pc.sctpTransport.Abort(""))
}

// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #7)
Expand Down
16 changes: 15 additions & 1 deletion sctptransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,28 @@ func (r *SCTPTransport) Start(SCTPCapabilities) error {
return nil
}

// Abort send the abort message and stops the SCTPTransport
func (r *SCTPTransport) Abort(reason string) error {
r.lock.Lock()
defer r.lock.Unlock()
if r.sctpAssociation == nil {
return nil
}
r.sctpAssociation.Abort(reason)

r.sctpAssociation = nil
r.state = SCTPTransportStateClosed

return nil
}

// Stop send the abort message and stops the SCTPTransport
func (r *SCTPTransport) Stop() error {
r.lock.Lock()
defer r.lock.Unlock()
if r.sctpAssociation == nil {
return nil
}
r.sctpAssociation.Abort("")
err := r.sctpAssociation.Close()
if err != nil {
return err
Expand Down

0 comments on commit 361fc46

Please sign in to comment.