address static check suggestions

This commit is contained in:
Tyler Stiene 2021-04-06 22:34:38 -04:00
parent a8f2574370
commit 177553f3a4
4 changed files with 20 additions and 23 deletions

View File

@ -168,8 +168,8 @@ func (b *BridgeState) startBridge() {
go b.DiscordStream.discordSendPCM(ctx, &wg, cancel, toDiscord) go b.DiscordStream.discordSendPCM(ctx, &wg, cancel, toDiscord)
// Monitor Mumble // Monitor Mumble
wg.Add(1)
go func() { go func() {
wg.Add(1)
ticker := time.NewTicker(500 * time.Millisecond) ticker := time.NewTicker(500 * time.Millisecond)
for { for {
select { select {

View File

@ -211,7 +211,7 @@ func (l *DiscordListener) voiceUpdate(s *discordgo.Session, event *discordgo.Voi
// Remove users that are no longer connected // Remove users that are no longer connected
for id := range l.Bridge.DiscordUsers { for id := range l.Bridge.DiscordUsers {
if l.Bridge.DiscordUsers[id].seen == false { if !l.Bridge.DiscordUsers[id].seen {
log.Println("User left Discord channel " + l.Bridge.DiscordUsers[id].username) log.Println("User left Discord channel " + l.Bridge.DiscordUsers[id].username)
if l.Bridge.Connected && !l.Bridge.BridgeConfig.MumbleDisableText { if l.Bridge.Connected && !l.Bridge.BridgeConfig.MumbleDisableText {
l.Bridge.MumbleClient.Do(func() { l.Bridge.MumbleClient.Do(func() {

View File

@ -87,8 +87,8 @@ func (dd *DiscordDuplex) discordSendPCM(ctx context.Context, wg *sync.WaitGroup,
continue continue
} }
if dd.Bridge.DiscordVoice.Ready == false || dd.Bridge.DiscordVoice.OpusSend == nil { if !dd.Bridge.DiscordVoice.Ready || dd.Bridge.DiscordVoice.OpusSend == nil {
if lastReady == true { if lastReady {
OnError(fmt.Sprintf("Discordgo not ready for opus packets. %+v : %+v", dd.Bridge.DiscordVoice.Ready, dd.Bridge.DiscordVoice.OpusSend), nil) OnError(fmt.Sprintf("Discordgo not ready for opus packets. %+v : %+v", dd.Bridge.DiscordVoice.Ready, dd.Bridge.DiscordVoice.OpusSend), nil)
readyTimeout = time.AfterFunc(30*time.Second, func() { readyTimeout = time.AfterFunc(30*time.Second, func() {
log.Println("set ready timeout") log.Println("set ready timeout")
@ -97,7 +97,7 @@ func (dd *DiscordDuplex) discordSendPCM(ctx context.Context, wg *sync.WaitGroup,
lastReady = false lastReady = false
} }
continue continue
} else if lastReady == false { } else if !lastReady {
fmt.Println("Discordgo ready to send opus packets") fmt.Println("Discordgo ready to send opus packets")
lastReady = true lastReady = true
readyTimeout.Stop() readyTimeout.Stop()
@ -123,8 +123,8 @@ func (dd *DiscordDuplex) discordReceivePCM(ctx context.Context, wg *sync.WaitGro
wg.Add(1) wg.Add(1)
for { for {
if dd.Bridge.DiscordVoice.Ready == false || dd.Bridge.DiscordVoice.OpusRecv == nil { if !dd.Bridge.DiscordVoice.Ready || dd.Bridge.DiscordVoice.OpusRecv == nil {
if lastReady == true { if lastReady {
OnError(fmt.Sprintf("Discordgo not to receive opus packets. %+v : %+v", dd.Bridge.DiscordVoice.Ready, dd.Bridge.DiscordVoice.OpusSend), nil) OnError(fmt.Sprintf("Discordgo not to receive opus packets. %+v : %+v", dd.Bridge.DiscordVoice.Ready, dd.Bridge.DiscordVoice.OpusSend), nil)
readyTimeout = time.AfterFunc(30*time.Second, func() { readyTimeout = time.AfterFunc(30*time.Second, func() {
log.Println("set ready timeout") log.Println("set ready timeout")
@ -133,7 +133,7 @@ func (dd *DiscordDuplex) discordReceivePCM(ctx context.Context, wg *sync.WaitGro
lastReady = false lastReady = false
} }
continue continue
} else if lastReady == false { } else if !lastReady {
fmt.Println("Discordgo ready to receive packets") fmt.Println("Discordgo ready to receive packets")
lastReady = true lastReady = true
readyTimeout.Stop() readyTimeout.Stop()
@ -222,7 +222,7 @@ func (dd *DiscordDuplex) fromDiscordMixer(ctx context.Context, wg *sync.WaitGrou
for i := range dd.fromDiscordMap { for i := range dd.fromDiscordMap {
if len(dd.fromDiscordMap[i].pcm) > 0 { if len(dd.fromDiscordMap[i].pcm) > 0 {
sendAudio = true sendAudio = true
if dd.fromDiscordMap[i].streaming == false { if !dd.fromDiscordMap[i].streaming {
x := dd.fromDiscordMap[i] x := dd.fromDiscordMap[i]
x.streaming = true x.streaming = true
dd.fromDiscordMap[i] = x dd.fromDiscordMap[i] = x
@ -231,7 +231,7 @@ func (dd *DiscordDuplex) fromDiscordMixer(ctx context.Context, wg *sync.WaitGrou
x1 := (<-dd.fromDiscordMap[i].pcm) x1 := (<-dd.fromDiscordMap[i].pcm)
internalMixerArr = append(internalMixerArr, x1) internalMixerArr = append(internalMixerArr, x1)
} else { } else {
if dd.fromDiscordMap[i].streaming == true { if dd.fromDiscordMap[i].streaming {
x := dd.fromDiscordMap[i] x := dd.fromDiscordMap[i]
x.streaming = false x.streaming = false
dd.fromDiscordMap[i] = x dd.fromDiscordMap[i] = x

View File

@ -29,21 +29,18 @@ func (m MumbleDuplex) OnAudioStream(e *gumble.AudioStreamEvent) {
mutex.Unlock() mutex.Unlock()
go func() { go func() {
// TODO kill go routine on cleanup name := e.User.Name
log.Println("new mumble audio stream", e.User.Name) log.Println("new mumble audio stream", name)
for { for p := range e.C {
select { // log.Println("audio packet", p.Sender.Name, len(p.AudioBuffer))
case p := <-e.C:
// log.Println("audio packet", p.Sender.Name, len(p.AudioBuffer))
// 480 per 10ms // 480 per 10ms
for i := 0; i < len(p.AudioBuffer)/480; i++ { for i := 0; i < len(p.AudioBuffer)/480; i++ {
localMumbleArray <- p.AudioBuffer[480*i : 480*(i+1)] localMumbleArray <- p.AudioBuffer[480*i : 480*(i+1)]
}
} }
} }
log.Println("mumble audio stream ended", name)
}() }()
return
} }
func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, toDiscord chan []int16) { func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, toDiscord chan []int16) {
@ -70,7 +67,7 @@ func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, t
for i := 0; i < len(fromMumbleArr); i++ { for i := 0; i < len(fromMumbleArr); i++ {
if len(fromMumbleArr[i]) > 0 { if len(fromMumbleArr[i]) > 0 {
sendAudio = true sendAudio = true
if mumbleStreamingArr[i] == false { if !mumbleStreamingArr[i] {
mumbleStreamingArr[i] = true mumbleStreamingArr[i] = true
// log.Println("mumble starting", i) // log.Println("mumble starting", i)
} }
@ -78,7 +75,7 @@ func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, t
x1 := (<-fromMumbleArr[i]) x1 := (<-fromMumbleArr[i])
internalMixerArr = append(internalMixerArr, x1) internalMixerArr = append(internalMixerArr, x1)
} else { } else {
if mumbleStreamingArr[i] == true { if mumbleStreamingArr[i] {
mumbleStreamingArr[i] = false mumbleStreamingArr[i] = false
// log.Println("mumble stopping", i) // log.Println("mumble stopping", i)
} }