Support Gateway v4
This adds support for gateway v4 (which we're technically already running; whoops). Really it just moves the version to the URL, and explicitly uses JSON as the encoding. Everything should be supported from previous commits.
This commit is contained in:
parent
33f2fa8d81
commit
ecc6e884c4
1 changed files with 7 additions and 2 deletions
9
wsapi.go
9
wsapi.go
|
@ -15,6 +15,7 @@ import (
|
||||||
"compress/zlib"
|
"compress/zlib"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -25,6 +26,8 @@ import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var GATEWAY_VERSION int = 4
|
||||||
|
|
||||||
type handshakeProperties struct {
|
type handshakeProperties struct {
|
||||||
OS string `json:"$os"`
|
OS string `json:"$os"`
|
||||||
Browser string `json:"$browser"`
|
Browser string `json:"$browser"`
|
||||||
|
@ -34,7 +37,6 @@ type handshakeProperties struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type handshakeData struct {
|
type handshakeData struct {
|
||||||
Version int `json:"v"`
|
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
Properties handshakeProperties `json:"properties"`
|
Properties handshakeProperties `json:"properties"`
|
||||||
LargeThreshold int `json:"large_threshold"`
|
LargeThreshold int `json:"large_threshold"`
|
||||||
|
@ -68,6 +70,9 @@ func (s *Session) Open() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the version and encoding to the URL
|
||||||
|
g = g + fmt.Sprintf("?v=%v&encoding=json", GATEWAY_VERSION)
|
||||||
|
|
||||||
header := http.Header{}
|
header := http.Header{}
|
||||||
header.Add("accept-encoding", "zlib")
|
header.Add("accept-encoding", "zlib")
|
||||||
|
|
||||||
|
@ -78,7 +83,7 @@ func (s *Session) Open() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.wsConn.WriteJSON(handshakeOp{2, handshakeData{3, s.Token, handshakeProperties{runtime.GOOS, "Discordgo v" + VERSION, "", "", ""}, 250, s.Compress}})
|
err = s.wsConn.WriteJSON(handshakeOp{2, handshakeData{s.Token, handshakeProperties{runtime.GOOS, "Discordgo v" + VERSION, "", "", ""}, 250, s.Compress}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue