diff --git a/structs.go b/structs.go index 46ab11d..7275ed4 100644 --- a/structs.go +++ b/structs.go @@ -46,6 +46,7 @@ type Session struct { OnMessageAck func(*Session, *MessageAck) OnUserUpdate func(*Session, *User) OnPresenceUpdate func(*Session, *PresenceUpdate) + OnVoiceServerUpdate func(*Session, *VoiceServerUpdate) OnVoiceStateUpdate func(*Session, *VoiceState) OnChannelCreate func(*Session, *Channel) OnChannelUpdate func(*Session, *Channel) diff --git a/wsapi.go b/wsapi.go index 8bcfefa..f2d055c 100644 --- a/wsapi.go +++ b/wsapi.go @@ -316,12 +316,21 @@ func (s *Session) event(messageType int, message []byte) { return } case "VOICE_SERVER_UPDATE": - // TEMP CODE FOR TESTING VOICE + if s.Voice == nil && s.OnVoiceServerUpdate == nil { + break + } var st *VoiceServerUpdate if err = unmarshalEvent(e, &st); err == nil { - s.onVoiceServerUpdate(st) + if s.Voice != nil { + s.onVoiceServerUpdate(st) + } + if s.OnVoiceServerUpdate != nil { + s.OnVoiceServerUpdate(s, st) + } + } + if s.OnVoiceServerUpdate != nil { + return } - return case "VOICE_STATE_UPDATE": if s.Voice == nil && s.OnVoiceStateUpdate == nil { break @@ -333,9 +342,11 @@ func (s *Session) event(messageType int, message []byte) { } if s.OnVoiceStateUpdate != nil { s.OnVoiceStateUpdate(s, st) - return } } + if s.OnVoiceStateUpdate != nil { + return + } case "USER_UPDATE": if s.OnUserUpdate != nil { var st *User @@ -782,11 +793,6 @@ func (s *Session) onVoiceStateUpdate(st *VoiceState) { // connection and should happen after the VOICE_STATE event. func (s *Session) onVoiceServerUpdate(st *VoiceServerUpdate) { - // This shouldn't ever be the case, I don't think. - if s.Voice == nil { - return - } - // Store values for later use s.Voice.token = st.Token s.Voice.endpoint = st.Endpoint