From 20f5db7e500aa64ba96ed931bb6fb296ec0ea539 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Thu, 23 Aug 2018 18:44:50 -0400 Subject: [PATCH] feature: add VSU forwarding to player this allows VSUs to be forwarded without needing to destroy and recreate a player --- player.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/player.go b/player.go index c916815..485c4e6 100644 --- a/player.go +++ b/player.go @@ -121,6 +121,29 @@ func (player *Player) Volume(volume int) error { 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 func (player *Player) Destroy() error { msg := message{