Make datachannel optional for publisher (#2686)

This commit is contained in:
cnderrauber
2024-04-26 15:24:41 +08:00
committed by GitHub
parent 37346774bb
commit 90de06ce02
2 changed files with 24 additions and 6 deletions
-1
View File
@@ -987,7 +987,6 @@ func (p *ParticipantImpl) SetMigrateState(s types.MigrateState) {
p.TransportManager.ProcessPendingPublisherOffer()
case types.MigrateStateComplete:
p.TransportManager.ProcessPendingPublisherDataChannels()
}
+24 -5
View File
@@ -149,10 +149,12 @@ type PCTransport struct {
lock sync.RWMutex
reliableDC *webrtc.DataChannel
reliableDCOpened bool
lossyDC *webrtc.DataChannel
lossyDCOpened bool
firstOfferReceived bool
firstOfferNoDataChannel bool
reliableDC *webrtc.DataChannel
reliableDCOpened bool
lossyDC *webrtc.DataChannel
lossyDCOpened bool
iceStartedAt time.Time
iceConnectedAt time.Time
@@ -694,7 +696,9 @@ func (t *PCTransport) isFullyEstablished() bool {
t.lock.RLock()
defer t.lock.RUnlock()
return t.reliableDCOpened && t.lossyDCOpened && !t.connectedAt.IsZero()
dataChannelReady := t.firstOfferNoDataChannel || (t.reliableDCOpened && t.lossyDCOpened)
return dataChannelReady && !t.connectedAt.IsZero()
}
func (t *PCTransport) SetPreferTCP(preferTCP bool) {
@@ -1698,6 +1702,21 @@ func (t *PCTransport) handleRemoteOfferReceived(sd *webrtc.SessionDescription) e
if err != nil {
return nil
}
t.lock.Lock()
if !t.firstOfferReceived {
t.firstOfferReceived = true
var dataChannelFound bool
for _, media := range parsed.MediaDescriptions {
if strings.EqualFold(media.MediaName.Media, "application") {
dataChannelFound = true
break
}
}
t.firstOfferNoDataChannel = !dataChannelFound
}
t.lock.Unlock()
iceCredential, offerRestartICE, err := t.isRemoteOfferRestartICE(parsed)
if err != nil {
return errors.Wrap(err, "check remote offer restart ice failed")