forked from pothtonswer/discordmuffin
Fix incorrect handling of VOICE_SERVER_UPDATE
With this change, discordgo now properly supports VOICE_SERVER_UPDATE events and will upon request close existing connections and then re-open the connection to the new voice endpoint. This allows voice gateway redirects and voice region changes to work even while a client is sending audio.
This commit is contained in:
parent
1a4bb2a004
commit
250579eb3a
1 changed files with 11 additions and 27 deletions
38
wsapi.go
38
wsapi.go
|
@ -363,13 +363,11 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (voice *Voi
|
||||||
// Create a new voice session
|
// Create a new voice session
|
||||||
// TODO review what all these things are for....
|
// TODO review what all these things are for....
|
||||||
voice = &VoiceConnection{
|
voice = &VoiceConnection{
|
||||||
GuildID: gID,
|
GuildID: gID,
|
||||||
ChannelID: cID,
|
ChannelID: cID,
|
||||||
deaf: deaf,
|
deaf: deaf,
|
||||||
mute: mute,
|
mute: mute,
|
||||||
session: s,
|
session: s,
|
||||||
connected: make(chan bool),
|
|
||||||
sessionRecv: make(chan string),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store voice in VoiceConnections map for this GuildID
|
// Store voice in VoiceConnections map for this GuildID
|
||||||
|
@ -425,9 +423,6 @@ func (s *Session) onVoiceStateUpdate(se *Session, st *VoiceStateUpdate) {
|
||||||
// Store the SessionID for later use.
|
// Store the SessionID for later use.
|
||||||
voice.UserID = self.ID // TODO: Review
|
voice.UserID = self.ID // TODO: Review
|
||||||
voice.sessionID = st.SessionID
|
voice.sessionID = st.SessionID
|
||||||
|
|
||||||
// TODO: Consider this...
|
|
||||||
// voice.sessionRecv <- st.SessionID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// onVoiceServerUpdate handles the Voice Server Update data websocket event.
|
// onVoiceServerUpdate handles the Voice Server Update data websocket event.
|
||||||
|
@ -444,29 +439,18 @@ func (s *Session) onVoiceServerUpdate(se *Session, st *VoiceServerUpdate) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If currently connected to voice ws/udp, then disconnect.
|
||||||
|
// Has no effect if not connected.
|
||||||
|
voice.Close()
|
||||||
|
|
||||||
// Store values for later use
|
// Store values for later use
|
||||||
voice.token = st.Token
|
voice.token = st.Token
|
||||||
voice.endpoint = st.Endpoint
|
voice.endpoint = st.Endpoint
|
||||||
voice.GuildID = st.GuildID
|
voice.GuildID = st.GuildID
|
||||||
|
|
||||||
// If currently connected to voice ws/udp, then disconnect.
|
// Open a conenction to the voice server
|
||||||
// Has no effect if not connected.
|
|
||||||
// voice.Close()
|
|
||||||
|
|
||||||
// Wait for the sessionID from onVoiceStateUpdate
|
|
||||||
// voice.sessionID = <-voice.sessionRecv
|
|
||||||
// TODO review above
|
|
||||||
// wouldn't this cause a huge problem, if it's just a guild server
|
|
||||||
// update.. ?
|
|
||||||
// I could add a timeout loop of some sort and also check if the
|
|
||||||
// sessionID doesn't or does exist already...
|
|
||||||
// something.. a bit smarter.
|
|
||||||
|
|
||||||
// We now have enough information to open a voice websocket conenction
|
|
||||||
// so, that's what the next call does.
|
|
||||||
err := voice.open()
|
err := voice.open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("onVoiceServerUpdate Voice.Open error: ", err)
|
s.log(LogError, "onVoiceServerUpdate voice.open, ", err)
|
||||||
// TODO better logging
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue