diff --git a/egressclient.go b/egressclient.go index 39dbfb09..a319f573 100644 --- a/egressclient.go +++ b/egressclient.go @@ -16,7 +16,6 @@ package lksdk import ( "context" - "net/http" "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" @@ -30,7 +29,8 @@ type EgressClient struct { func NewEgressClient(url string, apiKey string, secretKey string, opts ...twirp.ClientOption) *EgressClient { url = ToHttpURL(url) - client := livekit.NewEgressProtobufClient(url, &http.Client{}, opts...) + httpClient := DefaultHttpClientProvider.newHttpClient("egress") + client := livekit.NewEgressProtobufClient(url, httpClient, opts...) return &EgressClient{ egressClient: client, authBase: authBase{ diff --git a/httpclientprovider.go b/httpclientprovider.go new file mode 100644 index 00000000..fa2ebac4 --- /dev/null +++ b/httpclientprovider.go @@ -0,0 +1,21 @@ +package lksdk + +import "net/http" + +type HttpClientProvider struct { + NewHttpClient func(name string) *http.Client +} + +var DefaultHttpClientProvider = &HttpClientProvider{} + +func (p *HttpClientProvider) newHttpClient(name string) *http.Client { + fn := p.NewHttpClient + if fn == nil { + fn = defaultNewHttpClient + } + return fn(name) +} + +func defaultNewHttpClient(name string) *http.Client { + return &http.Client{} +} diff --git a/ingressclient.go b/ingressclient.go index 57c04f92..48d3b97e 100644 --- a/ingressclient.go +++ b/ingressclient.go @@ -16,7 +16,6 @@ package lksdk import ( "context" - "net/http" "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" @@ -30,7 +29,8 @@ type IngressClient struct { func NewIngressClient(url string, apiKey string, secretKey string, opts ...twirp.ClientOption) *IngressClient { url = ToHttpURL(url) - client := livekit.NewIngressProtobufClient(url, &http.Client{}, opts...) + httpClient := DefaultHttpClientProvider.newHttpClient("ingress") + client := livekit.NewIngressProtobufClient(url, httpClient, opts...) return &IngressClient{ ingressClient: client, authBase: authBase{ diff --git a/roomclient.go b/roomclient.go index b4901c8d..56d740aa 100644 --- a/roomclient.go +++ b/roomclient.go @@ -16,7 +16,6 @@ package lksdk import ( "context" - "net/http" "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" @@ -30,7 +29,8 @@ type RoomServiceClient struct { func NewRoomServiceClient(url string, apiKey string, secretKey string, opts ...twirp.ClientOption) *RoomServiceClient { url = ToHttpURL(url) - client := livekit.NewRoomServiceProtobufClient(url, &http.Client{}, opts...) + httpClient := DefaultHttpClientProvider.newHttpClient("room_service") + client := livekit.NewRoomServiceProtobufClient(url, httpClient, opts...) return &RoomServiceClient{ roomService: client, authBase: authBase{ diff --git a/sipclient.go b/sipclient.go index 7fc86f25..dda28647 100644 --- a/sipclient.go +++ b/sipclient.go @@ -16,7 +16,6 @@ package lksdk import ( "context" - "net/http" "github.com/livekit/protocol/auth" "github.com/livekit/protocol/livekit" @@ -29,8 +28,9 @@ type SIPClient struct { } func NewSIPClient(url string, apiKey string, secretKey string, opts ...twirp.ClientOption) *SIPClient { + httpClient := DefaultHttpClientProvider.newHttpClient("sip") return &SIPClient{ - sipClient: livekit.NewSIPProtobufClient(ToHttpURL(url), &http.Client{}, opts...), + sipClient: livekit.NewSIPProtobufClient(ToHttpURL(url), httpClient, opts...), authBase: authBase{ apiKey: apiKey, apiSecret: secretKey,