From 177553f3a4ea86f3a046bc8db3040a5f0f83cec3 Mon Sep 17 00:00:00 2001 From: Tyler Stiene Date: Tue, 6 Apr 2021 22:34:38 -0400 Subject: [PATCH] address static check suggestions --- bridge.go | 2 +- discord-handlers.go | 2 +- discord.go | 16 ++++++++-------- mumble.go | 23 ++++++++++------------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/bridge.go b/bridge.go index 5630adf..571ed0c 100644 --- a/bridge.go +++ b/bridge.go @@ -168,8 +168,8 @@ func (b *BridgeState) startBridge() { go b.DiscordStream.discordSendPCM(ctx, &wg, cancel, toDiscord) // Monitor Mumble + wg.Add(1) go func() { - wg.Add(1) ticker := time.NewTicker(500 * time.Millisecond) for { select { diff --git a/discord-handlers.go b/discord-handlers.go index 5118693..58f3ac2 100644 --- a/discord-handlers.go +++ b/discord-handlers.go @@ -211,7 +211,7 @@ func (l *DiscordListener) voiceUpdate(s *discordgo.Session, event *discordgo.Voi // Remove users that are no longer connected 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) if l.Bridge.Connected && !l.Bridge.BridgeConfig.MumbleDisableText { l.Bridge.MumbleClient.Do(func() { diff --git a/discord.go b/discord.go index 44befca..3fa8518 100644 --- a/discord.go +++ b/discord.go @@ -87,8 +87,8 @@ func (dd *DiscordDuplex) discordSendPCM(ctx context.Context, wg *sync.WaitGroup, continue } - if dd.Bridge.DiscordVoice.Ready == false || dd.Bridge.DiscordVoice.OpusSend == nil { - if lastReady == true { + if !dd.Bridge.DiscordVoice.Ready || dd.Bridge.DiscordVoice.OpusSend == nil { + if lastReady { 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() { log.Println("set ready timeout") @@ -97,7 +97,7 @@ func (dd *DiscordDuplex) discordSendPCM(ctx context.Context, wg *sync.WaitGroup, lastReady = false } continue - } else if lastReady == false { + } else if !lastReady { fmt.Println("Discordgo ready to send opus packets") lastReady = true readyTimeout.Stop() @@ -123,8 +123,8 @@ func (dd *DiscordDuplex) discordReceivePCM(ctx context.Context, wg *sync.WaitGro wg.Add(1) for { - if dd.Bridge.DiscordVoice.Ready == false || dd.Bridge.DiscordVoice.OpusRecv == nil { - if lastReady == true { + if !dd.Bridge.DiscordVoice.Ready || dd.Bridge.DiscordVoice.OpusRecv == nil { + if lastReady { 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() { log.Println("set ready timeout") @@ -133,7 +133,7 @@ func (dd *DiscordDuplex) discordReceivePCM(ctx context.Context, wg *sync.WaitGro lastReady = false } continue - } else if lastReady == false { + } else if !lastReady { fmt.Println("Discordgo ready to receive packets") lastReady = true readyTimeout.Stop() @@ -222,7 +222,7 @@ func (dd *DiscordDuplex) fromDiscordMixer(ctx context.Context, wg *sync.WaitGrou for i := range dd.fromDiscordMap { if len(dd.fromDiscordMap[i].pcm) > 0 { sendAudio = true - if dd.fromDiscordMap[i].streaming == false { + if !dd.fromDiscordMap[i].streaming { x := dd.fromDiscordMap[i] x.streaming = true dd.fromDiscordMap[i] = x @@ -231,7 +231,7 @@ func (dd *DiscordDuplex) fromDiscordMixer(ctx context.Context, wg *sync.WaitGrou x1 := (<-dd.fromDiscordMap[i].pcm) internalMixerArr = append(internalMixerArr, x1) } else { - if dd.fromDiscordMap[i].streaming == true { + if dd.fromDiscordMap[i].streaming { x := dd.fromDiscordMap[i] x.streaming = false dd.fromDiscordMap[i] = x diff --git a/mumble.go b/mumble.go index 4f99c70..66a6a4a 100644 --- a/mumble.go +++ b/mumble.go @@ -29,21 +29,18 @@ func (m MumbleDuplex) OnAudioStream(e *gumble.AudioStreamEvent) { mutex.Unlock() go func() { - // TODO kill go routine on cleanup - log.Println("new mumble audio stream", e.User.Name) - for { - select { - case p := <-e.C: - // log.Println("audio packet", p.Sender.Name, len(p.AudioBuffer)) + name := e.User.Name + log.Println("new mumble audio stream", name) + for p := range e.C { + // log.Println("audio packet", p.Sender.Name, len(p.AudioBuffer)) - // 480 per 10ms - for i := 0; i < len(p.AudioBuffer)/480; i++ { - localMumbleArray <- p.AudioBuffer[480*i : 480*(i+1)] - } + // 480 per 10ms + for i := 0; i < len(p.AudioBuffer)/480; i++ { + 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) { @@ -70,7 +67,7 @@ func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, t for i := 0; i < len(fromMumbleArr); i++ { if len(fromMumbleArr[i]) > 0 { sendAudio = true - if mumbleStreamingArr[i] == false { + if !mumbleStreamingArr[i] { mumbleStreamingArr[i] = true // log.Println("mumble starting", i) } @@ -78,7 +75,7 @@ func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, t x1 := (<-fromMumbleArr[i]) internalMixerArr = append(internalMixerArr, x1) } else { - if mumbleStreamingArr[i] == true { + if mumbleStreamingArr[i] { mumbleStreamingArr[i] = false // log.Println("mumble stopping", i) }