From eb156d2f8ccd54e911a7d98c4bab77c279193d60 Mon Sep 17 00:00:00 2001 From: boks1971 Date: Mon, 18 Aug 2025 08:55:48 +0530 Subject: [PATCH] use the available peer connection --- pkg/rtc/transportmanager.go | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/pkg/rtc/transportmanager.go b/pkg/rtc/transportmanager.go index b44c0f8ae..8d714fb89 100644 --- a/pkg/rtc/transportmanager.go +++ b/pkg/rtc/transportmanager.go @@ -649,20 +649,38 @@ func (t *TransportManager) GetICEConnectionInfo() []*types.ICEConnectionInfo { } func (t *TransportManager) getTransport(isPrimary bool) *PCTransport { - pcTransport := t.publisher - if (isPrimary && t.params.SubscriberAsPrimary) || (!isPrimary && !t.params.SubscriberAsPrimary) { - pcTransport = t.subscriber - } + switch { + case t.publisher == nil: + return t.subscriber - return pcTransport + case t.subscriber == nil: + return t.publisher + + default: + pcTransport := t.publisher + if (isPrimary && t.params.SubscriberAsPrimary) || (!isPrimary && !t.params.SubscriberAsPrimary) { + pcTransport = t.subscriber + } + + return pcTransport + } } func (t *TransportManager) getLowestPriorityConnectionType() types.ICEConnectionType { - ctype := t.publisher.GetICEConnectionType() - if stype := t.subscriber.GetICEConnectionType(); stype > ctype { - ctype = stype + switch { + case t.publisher == nil: + return t.subscriber.GetICEConnectionType() + + case t.subscriber == nil: + return t.publisher.GetICEConnectionType() + + default: + ctype := t.publisher.GetICEConnectionType() + if stype := t.subscriber.GetICEConnectionType(); stype > ctype { + ctype = stype + } + return ctype } - return ctype } func (t *TransportManager) handleConnectionFailed(isShortLived bool) {