Skip to content

Commit

Permalink
export client params options helper (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwe authored Mar 22, 2024
1 parent 0d9caad commit 9b0ad21
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rpc/egress_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewEgressClient(params ClientParams) (EgressClient, error) {
return nil, nil
}

opts := clientOptions(params)
opts := params.Options()
timeout := params.Timeout
if timeout < 10*time.Second {
timeout = 10 * time.Second
Expand Down
2 changes: 1 addition & 1 deletion rpc/ingress_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewIngressClient(params ClientParams) (IngressClient, error) {
if params.Bus == nil {
return nil, nil
}
opts := clientOptions(params)
opts := params.Options()

internalClient, err := NewIngressInternalClient(params.Bus, opts...)
if err != nil {
Expand Down
28 changes: 14 additions & 14 deletions rpc/typed_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ func NewClientParams(
}
}

func clientOptions(params ClientParams) []psrpc.ClientOption {
func (p *ClientParams) Options() []psrpc.ClientOption {
opts := make([]psrpc.ClientOption, 0, 4)
if params.BufferSize != 0 {
opts = append(opts, psrpc.WithClientChannelSize(params.BufferSize))
if p.BufferSize != 0 {
opts = append(opts, psrpc.WithClientChannelSize(p.BufferSize))
}
if params.Observer != nil {
opts = append(opts, middleware.WithClientMetrics(params.Observer))
if p.Observer != nil {
opts = append(opts, middleware.WithClientMetrics(p.Observer))
}
if params.Logger != nil {
opts = append(opts, WithClientLogger(params.Logger))
if p.Logger != nil {
opts = append(opts, WithClientLogger(p.Logger))
}
if params.MaxAttempts != 0 || params.Timeout != 0 || params.Backoff != 0 {
if p.MaxAttempts != 0 || p.Timeout != 0 || p.Backoff != 0 {
opts = append(opts, middleware.WithRPCRetries(middleware.RetryOptions{
MaxAttempts: params.MaxAttempts,
Timeout: params.Timeout,
Backoff: params.Backoff,
MaxAttempts: p.MaxAttempts,
Timeout: p.Timeout,
Backoff: p.Backoff,
}))
}
return opts
Expand Down Expand Up @@ -130,7 +130,7 @@ type TypedRoomClient = RoomClient[RoomTopic]
type TypedRoomServer = RoomServer[RoomTopic]

func NewTypedRoomClient(params ClientParams) (TypedRoomClient, error) {
return NewRoomClient[RoomTopic](params.Bus, clientOptions(params)...)
return NewRoomClient[RoomTopic](params.Bus, params.Options()...)
}

func NewTypedRoomServer(svc RoomServerImpl, bus psrpc.MessageBus, opts ...psrpc.ServerOption) (TypedRoomServer, error) {
Expand All @@ -142,7 +142,7 @@ type TypedParticipantClient = ParticipantClient[ParticipantTopic]
type TypedParticipantServer = ParticipantServer[ParticipantTopic]

func NewTypedParticipantClient(params ClientParams) (TypedParticipantClient, error) {
return NewParticipantClient[ParticipantTopic](params.Bus, clientOptions(params)...)
return NewParticipantClient[ParticipantTopic](params.Bus, params.Options()...)
}

func NewTypedParticipantServer(svc ParticipantServerImpl, bus psrpc.MessageBus, opts ...psrpc.ServerOption) (TypedParticipantServer, error) {
Expand All @@ -161,7 +161,7 @@ type keepalivePubSub struct {
}

func NewKeepalivePubSub(params ClientParams) (KeepalivePubSub, error) {
client, err := NewKeepaliveClient[livekit.NodeID](params.Bus, clientOptions(params)...)
client, err := NewKeepaliveClient[livekit.NodeID](params.Bus, params.Options()...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9b0ad21

Please sign in to comment.