feature: add VSU forwarding to player

this allows VSUs to be forwarded without needing to destroy and recreate
a player
This commit is contained in:
Christopher F 2018-08-23 18:44:50 -04:00
parent 25d8b0f862
commit 20f5db7e50
1 changed files with 23 additions and 0 deletions

View File

@ -121,6 +121,29 @@ func (player *Player) Volume(volume int) error {
return err return err
} }
// Forward will forward a new VOICE_SERVER_UPDATE to a Lavalink node for
// this player.
//
// This should always be used if a VOICE_SERVER_UPDATE is received for
// a guild which already has a player.
//
// To move a player to a new Node, first player.Destroy() it, and then
// create a new player on the new node.
func (player *Player) Forward(sessionID string, event VoiceServerUpdate) error {
msg := message{
Op: opVoiceUpdate,
GuildID: player.guildID,
SessionID: sessionID,
Event: event,
}
data, err := json.Marshal(msg)
if err != nil {
return err
}
err = player.node.wsConn.WriteMessage(websocket.TextMessage, data)
return err
}
// Destroy will destroy this player // Destroy will destroy this player
func (player *Player) Destroy() error { func (player *Player) Destroy() error {
msg := message{ msg := message{