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

Rename connectParams -> SignalClientConnectParams (to make it exportable) #540

Merged
merged 1 commit into from
Nov 15, 2024
Merged
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 engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type RTCEngine struct {

url string
token atomic.String
connParams *connectParams
connParams *SignalClientConnectParams

JoinTimeout time.Duration

Expand Down Expand Up @@ -138,7 +138,7 @@ func (e *RTCEngine) SetLogger(l protoLogger.Logger) {
}
}

func (e *RTCEngine) Join(url string, token string, params *connectParams) (*livekit.JoinResponse, error) {
func (e *RTCEngine) Join(url string, token string, params *SignalClientConnectParams) (*livekit.JoinResponse, error) {
res, err := e.client.Join(url, token, *params)
if err != nil {
return nil, err
Expand Down
20 changes: 10 additions & 10 deletions room.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type ConnectInfo struct {
}

// not exposed to users. clients should use ConnectOption
type connectParams struct {
type SignalClientConnectParams struct {
AutoSubscribe bool
Reconnect bool
DisableRegionDiscovery bool
Expand All @@ -103,44 +103,44 @@ type connectParams struct {
ICETransportPolicy webrtc.ICETransportPolicy
}

type ConnectOption func(*connectParams)
type ConnectOption func(*SignalClientConnectParams)

func WithAutoSubscribe(val bool) ConnectOption {
return func(p *connectParams) {
return func(p *SignalClientConnectParams) {
p.AutoSubscribe = val
}
}

// Retransmit buffer size to reponse to nack request,
// must be one of: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768
func WithRetransmitBufferSize(val uint16) ConnectOption {
return func(p *connectParams) {
return func(p *SignalClientConnectParams) {
p.RetransmitBufferSize = val
}
}

// WithPacer enables the use of a pacer on this connection
// A pacer helps to smooth out video packet rate to avoid overwhelming downstream. Learn more at: https://chromium.googlesource.com/external/webrtc/+/master/modules/pacing/g3doc/index.md
func WithPacer(pacer pacer.Factory) ConnectOption {
return func(p *connectParams) {
return func(p *SignalClientConnectParams) {
p.Pacer = pacer
}
}

func WithInterceptors(interceptors []interceptor.Factory) ConnectOption {
return func(p *connectParams) {
return func(p *SignalClientConnectParams) {
p.Interceptors = interceptors
}
}

func WithICETransportPolicy(iceTransportPolicy webrtc.ICETransportPolicy) ConnectOption {
return func(p *connectParams) {
return func(p *SignalClientConnectParams) {
p.ICETransportPolicy = iceTransportPolicy
}
}

func WithDisableRegionDiscovery() ConnectOption {
return func(p *connectParams) {
return func(p *SignalClientConnectParams) {
p.DisableRegionDiscovery = true
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ func (r *Room) PrepareConnection(url, token string) error {

// Join - joins the room as with default permissions
func (r *Room) Join(url string, info ConnectInfo, opts ...ConnectOption) error {
var params connectParams
var params SignalClientConnectParams
for _, opt := range opts {
opt(&params)
}
Expand Down Expand Up @@ -285,7 +285,7 @@ func (r *Room) Join(url string, info ConnectInfo, opts ...ConnectOption) error {

// JoinWithToken - customize participant options by generating your own token
func (r *Room) JoinWithToken(url, token string, opts ...ConnectOption) error {
params := &connectParams{
params := &SignalClientConnectParams{
AutoSubscribe: true,
}
for _, opt := range opts {
Expand Down
6 changes: 3 additions & 3 deletions signalclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (c *SignalClient) IsStarted() bool {
return c.isStarted.Load()
}

func (c *SignalClient) Join(urlPrefix string, token string, params connectParams) (*livekit.JoinResponse, error) {
func (c *SignalClient) Join(urlPrefix string, token string, params SignalClientConnectParams) (*livekit.JoinResponse, error) {
res, err := c.connect(urlPrefix, token, params, "")
if err != nil {
return nil, err
Expand All @@ -97,7 +97,7 @@ func (c *SignalClient) Join(urlPrefix string, token string, params connectParams

// Reconnect starts a new WebSocket connection to the server, passing in reconnect=1
// when successful, it'll return a ReconnectResponse; older versions of the server will not send back a ReconnectResponse
func (c *SignalClient) Reconnect(urlPrefix string, token string, params connectParams, participantSID string) (*livekit.ReconnectResponse, error) {
func (c *SignalClient) Reconnect(urlPrefix string, token string, params SignalClientConnectParams, participantSID string) (*livekit.ReconnectResponse, error) {
params.Reconnect = true
res, err := c.connect(urlPrefix, token, params, participantSID)
if err != nil {
Expand All @@ -121,7 +121,7 @@ func (c *SignalClient) Reconnect(urlPrefix string, token string, params connectP
return nil, nil
}

func (c *SignalClient) connect(urlPrefix string, token string, params connectParams, participantSID string) (*livekit.SignalResponse, error) {
func (c *SignalClient) connect(urlPrefix string, token string, params SignalClientConnectParams, participantSID string) (*livekit.SignalResponse, error) {
if urlPrefix == "" {
return nil, ErrURLNotProvided
}
Expand Down
4 changes: 2 additions & 2 deletions signalclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
func TestSignalClient_Join(t *testing.T) {
t.Run("rejects empty URLs", func(t *testing.T) {
c := NewSignalClient()
_, err := c.Join("", "", connectParams{})
_, err := c.Join("", "", SignalClientConnectParams{})
require.Equal(t, ErrURLNotProvided, err)
})

t.Run("errors on invalid URLs", func(t *testing.T) {
c := NewSignalClient()
_, err := c.Join("https://invalid-livekit-url", "", connectParams{})
_, err := c.Join("https://invalid-livekit-url", "", SignalClientConnectParams{})
require.Error(t, err)
require.NotEqual(t, ErrURLNotProvided, err)
})
Expand Down