mirror of
https://github.com/stryan/mumble-discord-bridge.git
synced 2024-12-27 17:05:40 -05:00
improve discord buffer packet drop message
kill the bridge if unable to send to discord for 5 seconds
This commit is contained in:
parent
649fe9f33e
commit
0f57c5d33a
@ -183,7 +183,7 @@ func (b *BridgeState) StartBridge() {
|
||||
// Start Passing Between
|
||||
|
||||
// From Mumble
|
||||
go b.MumbleStream.fromMumbleMixer(ctx, &wg, toDiscord)
|
||||
go b.MumbleStream.fromMumbleMixer(ctx, &wg, cancel, toDiscord)
|
||||
|
||||
// From Discord
|
||||
b.DiscordStream = &DiscordDuplex{
|
||||
|
@ -3,6 +3,7 @@ package bridge
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -50,12 +51,15 @@ func (m MumbleDuplex) OnAudioStream(e *gumble.AudioStreamEvent) {
|
||||
}()
|
||||
}
|
||||
|
||||
func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, toDiscord chan []int16) {
|
||||
func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, cancel context.CancelFunc, toDiscord chan []int16) {
|
||||
mumbleSleepTick.Start(10 * time.Millisecond)
|
||||
|
||||
sendAudio := false
|
||||
bufferWarning := false
|
||||
|
||||
droppingPackets := false
|
||||
droppingPacketCount := 0
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
for {
|
||||
@ -124,9 +128,24 @@ func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, t
|
||||
promToDiscordBufferSize.Set(float64(len(toDiscord)))
|
||||
select {
|
||||
case toDiscord <- outBuf:
|
||||
{
|
||||
if droppingPackets {
|
||||
log.Println("Discord buffer ok, total packets dropped " + strconv.Itoa(droppingPacketCount))
|
||||
droppingPackets = false
|
||||
}
|
||||
}
|
||||
default:
|
||||
log.Println("Error: toDiscord buffer full. Dropping packet")
|
||||
if !droppingPackets {
|
||||
log.Println("Error: toDiscord buffer full. Dropping packets")
|
||||
droppingPackets = true
|
||||
droppingPacketCount = 0
|
||||
}
|
||||
droppingPacketCount++
|
||||
promToDiscordDropped.Inc()
|
||||
if droppingPacketCount > 250 {
|
||||
log.Println("Discord Timeout")
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
|
||||
discrodSendSleepTick.Notify()
|
||||
|
Loading…
Reference in New Issue
Block a user