Skip to content

Commit

Permalink
Add dialer property in config (#1179)
Browse files Browse the repository at this point in the history
Co-authored-by: eeWynell <eewynell@gmail.com>
  • Loading branch information
uWynell and eeWynell committed Aug 13, 2022
1 parent c0803d0 commit 262e8ba
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
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

// 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

0 comments on commit 262e8ba

Please sign in to comment.