Log selected ICE candidate pair (#865)
* Log selected ICE candidate pair * simplify
This commit is contained in:
+35
-1
@@ -1283,8 +1283,38 @@ func (p *ParticipantImpl) handleDataMessage(kind livekit.DataPacket_Kind, data [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ParticipantImpl) logSelectedCandidatePair(isPrimary bool) {
|
||||||
|
pcTransport := p.publisher
|
||||||
|
if (isPrimary && p.SubscriberAsPrimary()) || (!isPrimary && !p.SubscriberAsPrimary()) {
|
||||||
|
pcTransport = p.subscriber
|
||||||
|
}
|
||||||
|
|
||||||
|
sctp := pcTransport.pc.SCTP()
|
||||||
|
if sctp == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
transport := sctp.Transport()
|
||||||
|
if transport == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
iceTransport := transport.ICETransport()
|
||||||
|
if iceTransport == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedCandidatePair, err := iceTransport.GetSelectedCandidatePair()
|
||||||
|
if err != nil {
|
||||||
|
pcTransport.Logger().Errorw("error getting selected ICE candidate pair", err)
|
||||||
|
} else {
|
||||||
|
pcTransport.Logger().Infow("selected ICE candidate pair", "pair", selectedCandidatePair)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) handlePrimaryStateChange(state webrtc.PeerConnectionState) {
|
func (p *ParticipantImpl) handlePrimaryStateChange(state webrtc.PeerConnectionState) {
|
||||||
if state == webrtc.PeerConnectionStateConnected {
|
if state == webrtc.PeerConnectionStateConnected {
|
||||||
|
p.logSelectedCandidatePair(true)
|
||||||
if !p.firstConnected.Swap(true) {
|
if !p.firstConnected.Swap(true) {
|
||||||
p.setDowntracksConnected()
|
p.setDowntracksConnected()
|
||||||
}
|
}
|
||||||
@@ -1302,9 +1332,11 @@ func (p *ParticipantImpl) handlePrimaryStateChange(state webrtc.PeerConnectionSt
|
|||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
if p.disconnectTimer != nil {
|
if p.disconnectTimer != nil {
|
||||||
p.disconnectTimer.Stop()
|
p.disconnectTimer.Stop()
|
||||||
|
p.disconnectTimer = nil
|
||||||
}
|
}
|
||||||
p.disconnectTimer = time.AfterFunc(disconnectCleanupDuration, func() {
|
p.disconnectTimer = time.AfterFunc(disconnectCleanupDuration, func() {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
|
p.disconnectTimer.Stop()
|
||||||
p.disconnectTimer = nil
|
p.disconnectTimer = nil
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
|
|
||||||
@@ -1329,7 +1361,9 @@ func (p *ParticipantImpl) handlePrimaryStateChange(state webrtc.PeerConnectionSt
|
|||||||
// for the secondary peer connection, we still need to handle when they become disconnected
|
// for the secondary peer connection, we still need to handle when they become disconnected
|
||||||
// instead of allowing them to silently fail.
|
// instead of allowing them to silently fail.
|
||||||
func (p *ParticipantImpl) handleSecondaryStateChange(state webrtc.PeerConnectionState) {
|
func (p *ParticipantImpl) handleSecondaryStateChange(state webrtc.PeerConnectionState) {
|
||||||
if state == webrtc.PeerConnectionStateFailed {
|
if state == webrtc.PeerConnectionStateConnected {
|
||||||
|
p.logSelectedCandidatePair(false)
|
||||||
|
} else if state == webrtc.PeerConnectionStateFailed {
|
||||||
// clients support resuming of connections when websocket becomes disconnected
|
// clients support resuming of connections when websocket becomes disconnected
|
||||||
p.closeSignalConnection()
|
p.closeSignalConnection()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,6 +212,10 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
|||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *PCTransport) Logger() logger.Logger {
|
||||||
|
return t.params.Logger
|
||||||
|
}
|
||||||
|
|
||||||
func (t *PCTransport) createPeerConnection() error {
|
func (t *PCTransport) createPeerConnection() error {
|
||||||
var bwe cc.BandwidthEstimator
|
var bwe cc.BandwidthEstimator
|
||||||
pc, me, err := newPeerConnection(t.params, func(estimator cc.BandwidthEstimator) {
|
pc, me, err := newPeerConnection(t.params, func(estimator cc.BandwidthEstimator) {
|
||||||
|
|||||||
Reference in New Issue
Block a user