mirror of
https://github.com/stryan/mumble-discord-bridge.git
synced 2024-12-30 09:55:40 -05:00
address static check suggestions
This commit is contained in:
parent
a8f2574370
commit
177553f3a4
@ -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
|
||||||
go func() {
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
ticker := time.NewTicker(500 * time.Millisecond)
|
ticker := time.NewTicker(500 * time.Millisecond)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -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() {
|
||||||
|
16
discord.go
16
discord.go
@ -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
|
||||||
|
15
mumble.go
15
mumble.go
@ -29,11 +29,9 @@ 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 {
|
|
||||||
case p := <-e.C:
|
|
||||||
// log.Println("audio packet", p.Sender.Name, len(p.AudioBuffer))
|
// log.Println("audio packet", p.Sender.Name, len(p.AudioBuffer))
|
||||||
|
|
||||||
// 480 per 10ms
|
// 480 per 10ms
|
||||||
@ -41,9 +39,8 @@ func (m MumbleDuplex) OnAudioStream(e *gumble.AudioStreamEvent) {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user