Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transceivers state change from inactive to active #2426

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 42 additions & 1 deletion peerconnection.go
Expand Up @@ -1104,7 +1104,10 @@
}
_ = t.SetCodecPreferences(filteredCodecs)
}

case direction == RTPTransceiverDirectionSendonly:
if t.Direction() == RTPTransceiverDirectionInactive {
t.setDirection(RTPTransceiverDirectionRecvonly)
}
case direction == RTPTransceiverDirectionRecvonly:
if t.Direction() == RTPTransceiverDirectionSendrecv {
t.setDirection(RTPTransceiverDirectionSendonly)
Expand Down Expand Up @@ -1894,6 +1897,44 @@
return t, nil
}

// ReuseTransceiverFromTrack Reuse old RtpTransceiver or Create a new RtpTransceiver and adds it to the set of transceivers.
func (pc *PeerConnection) ReuseTransceiverFromTrack(track TrackLocal, init ...RTPTransceiverInit) (t *RTPTransceiver, err error) {

Check warning on line 1901 in peerconnection.go

View check run for this annotation

Codecov / codecov/patch

peerconnection.go#L1900-L1901

Added lines #L1900 - L1901 were not covered by tests
if pc.isClosed.get() {
return nil, &rtcerr.InvalidStateError{Err: ErrConnectionClosed}
}
pc.mu.Lock()

Check warning on line 1905 in peerconnection.go

View check run for this annotation

Codecov / codecov/patch

peerconnection.go#L1904-L1905

Added lines #L1904 - L1905 were not covered by tests
defer pc.mu.Unlock()
for _, t := range pc.rtpTransceivers {
currentDirection := t.getCurrentDirection()
if !t.stopped && t.kind == track.Kind() && currentDirection == RTPTransceiverDirectionInactive {

Check warning on line 1909 in peerconnection.go

View check run for this annotation

Codecov / codecov/patch

peerconnection.go#L1908-L1909

Added lines #L1908 - L1909 were not covered by tests
sender, err := pc.api.NewRTPSender(track, pc.dtlsTransport)
if err == nil {
err = t.SetSender(sender, track)
if err != nil {
_ = sender.Stop()

Check warning on line 1914 in peerconnection.go

View check run for this annotation

Codecov / codecov/patch

peerconnection.go#L1913-L1914

Added lines #L1913 - L1914 were not covered by tests
t.setSender(nil)
}
} else {

Check warning on line 1917 in peerconnection.go

View check run for this annotation

Codecov / codecov/patch

peerconnection.go#L1916-L1917

Added lines #L1916 - L1917 were not covered by tests
return nil, err
}
pc.onNegotiationNeeded()
return t, nil
}
}
direction := RTPTransceiverDirectionSendrecv
if len(init) > 1 {
return nil, errPeerConnAddTransceiverFromTrackOnlyAcceptsOne
} else if len(init) == 1 {
direction = init[0].Direction
}
t, err = pc.newTransceiverFromTrack(direction, track)
if err != nil {
return nil, err
}
pc.addRTPTransceiver(t)
return

Check failure on line 1935 in peerconnection.go

View workflow job for this annotation

GitHub Actions / lint / Go

shadow: declaration of "err" shadows declaration at line 1926 (govet)
}

Check warning on line 1937 in peerconnection.go

View check run for this annotation

Codecov / codecov/patch

peerconnection.go#L1926-L1937

Added lines #L1926 - L1937 were not covered by tests
// AddTransceiverFromTrack Create a new RtpTransceiver(SendRecv or SendOnly) and add it to the set of transceivers.
func (pc *PeerConnection) AddTransceiverFromTrack(track TrackLocal, init ...RTPTransceiverInit) (t *RTPTransceiver, err error) {
if pc.isClosed.get() {
Expand All @@ -1916,7 +1957,7 @@
return
}

// CreateDataChannel creates a new DataChannel object with the given label

Check failure on line 1960 in peerconnection.go

View workflow job for this annotation

GitHub Actions / lint / Go

naked return in func `ReuseTransceiverFromTrack` with 35 lines of code (nakedret)
// and optional DataChannelInit used to configure properties of the
// underlying channel such as data reliability.
func (pc *PeerConnection) CreateDataChannel(label string, options *DataChannelInit) (*DataChannel, error) {
Expand Down