Skip to content
Open
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
21 changes: 20 additions & 1 deletion ws/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Client struct {
pingInterval time.Duration // Ping间隔
cache *larkcache.Cache
mu sync.Mutex

// alternative ws dialer
altDialer *ws.Dialer
}

type ClientOption func(cli *Client)
Expand Down Expand Up @@ -81,6 +84,13 @@ func WithDomain(domain string) ClientOption {
}
}

// WithAltWSDialer set customized websocket dialer, can be used with proxy.
func WithAltWSDialer(dialer *ws.Dialer) ClientOption {
return func(cli *Client) {
cli.altDialer = dialer
}
}

func NewClient(appId, appSecret string, opts ...ClientOption) *Client {
cli := &Client{
appID: appId,
Expand Down Expand Up @@ -149,7 +159,16 @@ func (c *Client) connect(ctx context.Context) (err error) {
connID := u.Query().Get(DeviceID)
serviceID := u.Query().Get(ServiceID)

conn, resp, err := ws.DefaultDialer.Dial(connUrl, nil)
var (
conn *ws.Conn
resp *http.Response
)
// use customized dialer if provided
if c.altDialer != nil {
conn, resp, err = c.altDialer.Dial(connUrl, nil)
} else {
conn, resp, err = ws.DefaultDialer.Dial(connUrl, nil)
}
if err != nil && resp == nil {
return
}
Expand Down