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

Add Dialer property to Session #1179

Merged
merged 1 commit into from Aug 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions discord.go
Expand Up @@ -17,6 +17,8 @@ import (
"net/http"
"runtime"
"time"

"github.com/gorilla/websocket"
)

// VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)
Expand All @@ -41,6 +43,7 @@ func New(token string) (s *Session, err error) {
ShardCount: 1,
MaxRestRetries: 3,
Client: &http.Client{Timeout: (20 * time.Second)},
Dialer: websocket.DefaultDialer,
UserAgent: "DiscordBot (https://github.com/bwmarrin/discordgo, v" + VERSION + ")",
sequence: new(int64),
LastHeartbeatAck: time.Now().UTC(),
Expand Down
3 changes: 3 additions & 0 deletions structs.go
Expand Up @@ -95,6 +95,9 @@ type Session struct {
// The http client used for REST requests
Client *http.Client

// The dialer used for WebSocket connection
Dialer *websocket.Dialer
uWynell marked this conversation as resolved.
Show resolved Hide resolved

// The user agent used for REST APIs
UserAgent string

Expand Down
2 changes: 1 addition & 1 deletion wsapi.go
Expand Up @@ -77,7 +77,7 @@ func (s *Session) Open() error {
s.log(LogInformational, "connecting to gateway %s", s.gateway)
header := http.Header{}
header.Add("accept-encoding", "zlib")
s.wsConn, _, err = websocket.DefaultDialer.Dial(s.gateway, header)
s.wsConn, _, err = s.Dialer.Dial(s.gateway, header)
if err != nil {
s.log(LogError, "error connecting to gateway %s, %s", s.gateway, err)
s.gateway = "" // clear cached gateway
Expand Down