@@ -39,8 +39,8 @@ import (
3939 "github.com/livekit/protocol/utils/traceid"
4040 "github.com/livekit/psrpc"
4141 lksdk "github.com/livekit/server-sdk-go/v2"
42+ "github.com/livekit/sipgo"
4243 "github.com/livekit/sipgo/sip"
43- "github.com/livekit/sipgo/transport"
4444
4545 "github.com/livekit/sip/pkg/config"
4646 "github.com/livekit/sip/pkg/stats"
@@ -1069,11 +1069,7 @@ func (c *sipOutbound) inviteDestinations(ctx context.Context, headers map[string
10691069 }
10701070 }
10711071
1072- tpl := c .transportLayer ()
1073- if tpl == nil {
1074- return unresolved
1075- }
1076- targets , err := tpl .ResolveTargets (ctx , uriTransport (c .uri ), c .uri .Host , c .uri .Port , c .uri .Scheme )
1072+ targets , err := c .c .sipCli .ResolveTargets (ctx , uriTransport (c .uri ), c .uri .Host , c .uri .Port , c .uri .Scheme )
10771073 if err != nil {
10781074 c .log .Warnw ("could not resolve destination, falling back to transport resolution" , err ,
10791075 "host" , c .uri .Host , "port" , c .uri .Port )
@@ -1197,15 +1193,6 @@ authLoop:
11971193 return req , resp , nil
11981194}
11991195
1200- // transportLayer returns sipgo's transport layer, or nil when the SIP client is
1201- // not the real one, as in tests that substitute their own.
1202- func (c * sipOutbound ) transportLayer () * transport.Layer {
1203- if c .c .sipCli == nil {
1204- return nil
1205- }
1206- return c .c .sipCli .TransportLayer ()
1207- }
1208-
12091196// uriTransport returns the transport a request to uri will use, matching how
12101197// sipgo derives it from the request.
12111198func uriTransport (uri * sip.Uri ) string {
@@ -1317,12 +1304,16 @@ func (c *sipOutbound) attemptInvite(ctx context.Context, dest string, callID sip
13171304
13181305 // Log the actual local port used for TCP connections from the DialPort range
13191306 if req .Transport () == "TCP" {
1320- if tpl := c .transportLayer (); tpl != nil {
1321- // The connection should be available after TransactionRequest creates it
1322- if dest := req .Destination (); dest != "" {
1323- if conn , err := tpl .GetConnection ("tcp" , dest ); err == nil && conn != nil {
1324- if tcpAddr , ok := conn .LocalAddr ().(* net.TCPAddr ); ok && tcpAddr != nil {
1325- c .log .Debugw ("TCP connection using port on cloud-sip side" , "port" , tcpAddr .Port )
1307+ // Type-assert to *sipgo.Client to access the embedded UserAgent
1308+ if sipClient , ok := c .c .sipCli .(* sipgo.Client ); ok {
1309+ if tpl := sipClient .TransportLayer (); tpl != nil {
1310+ // Try to get the connection using the destination address
1311+ // The connection should be available after TransactionRequest creates it
1312+ if dest := req .Destination (); dest != "" {
1313+ if conn , err := tpl .GetConnection ("tcp" , dest ); err == nil && conn != nil {
1314+ if tcpAddr , ok := conn .LocalAddr ().(* net.TCPAddr ); ok && tcpAddr != nil {
1315+ c .log .Debugw ("TCP connection using port on cloud-sip side" , "port" , tcpAddr .Port )
1316+ }
13261317 }
13271318 }
13281319 }
0 commit comments