Initial capabilities support for custom implementations

This commit is contained in:
Tyler 2019-10-13 14:07:59 -04:00
parent 8efc77cacc
commit 7eae103756
2 changed files with 28 additions and 0 deletions

View File

@ -23,6 +23,8 @@ type Lavalink struct {
nodes []*Node
players map[string]*Player
capabilities map[string]interface{}
BestNodeFunc func([]*Node) (*Node, error)
}
@ -133,3 +135,12 @@ func (lavalink *Lavalink) GetPlayer(guild string) (*Player, error) {
return p, nil
}
// Add capabilities mappings to the client, letting the server know what we support
func (lavalink *Lavalink) AddCapability(key string, i interface{}) {
if lavalink.capabilities == nil {
lavalink.capabilities = make(map[string]interface{})
}
lavalink.capabilities[key] = i
}

17
node.go
View File

@ -6,6 +6,7 @@ import (
"github.com/valyala/fastjson"
"net/http"
"strconv"
"strings"
"github.com/gorilla/websocket"
)
@ -71,6 +72,22 @@ func (node *Node) open() error {
header.Set("Num-Shards", node.manager.shards)
header.Set("User-Id", node.manager.userID)
if node.manager.capabilities != nil {
v := make([]string, 0)
for k, vals := range node.manager.capabilities {
b, err := json.Marshal(vals)
if err != nil {
continue
}
v = append(v, k+"="+string(b))
}
header.Set("Capabilities", strings.Join(v, ";"))
}
ws, resp, err := websocket.DefaultDialer.Dial(node.config.WebSocket, header)
if err != nil {