Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes it possible to change the HTTP client #465

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions egressclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package lksdk

import (
"context"
"net/http"

"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
Expand All @@ -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{
Expand Down
21 changes: 21 additions & 0 deletions httpclientprovider.go
Original file line number Diff line number Diff line change
@@ -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{}
}
4 changes: 2 additions & 2 deletions ingressclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package lksdk

import (
"context"
"net/http"

"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
Expand All @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions roomclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package lksdk

import (
"context"
"net/http"

"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
Expand All @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions sipclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package lksdk

import (
"context"
"net/http"

"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
Expand All @@ -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,
Expand Down
Loading