From c469a65ed6a8bc1522579eab39fde797d51c1015 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 5 Jan 2021 13:16:03 -0500 Subject: [PATCH] begin switching to mumble event listeners --- bridge.go | 13 +++++-------- handlers.go | 11 +++++++++++ main.go | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/bridge.go b/bridge.go index cd57238..d015741 100644 --- a/bridge.go +++ b/bridge.go @@ -12,6 +12,7 @@ import ( "github.com/bwmarrin/discordgo" "layeh.com/gumble/gumble" + "layeh.com/gumble/gumbleutil" ) type BridgeState struct { @@ -44,7 +45,9 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin if mumbleInsecure { tlsConfig.InsecureSkipVerify = true } - + config.Attach(gumbleutil.Listener{ + Connect: mumbleConnect, + }) mumble, err := gumble.DialWithDialer(new(net.Dialer), mumbleAddr, config, &tlsConfig) if err != nil { @@ -53,13 +56,6 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin } defer mumble.Disconnect() Bridge.Client = mumble - if BridgeConf.MumbleChannel != "" { - //join specified channel - startingChannel := mumble.Channels.Find(BridgeConf.MumbleChannel) - if startingChannel != nil { - mumble.Self.Move(startingChannel) - } - } // Shared Channels // Shared channels pass PCM information in 10ms chunks [480]int16 var toMumble = mumble.AudioOutgoing() @@ -71,6 +67,7 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin // Mumble go m.fromMumbleMixer(toDiscord, die) det := config.AudioListeners.Attach(m) + //Discord go discordReceivePCM(dgv, die) go fromDiscordMixer(toMumble, die) diff --git a/handlers.go b/handlers.go index c8451a3..6e33cb7 100644 --- a/handlers.go +++ b/handlers.go @@ -7,6 +7,7 @@ import ( "time" "github.com/bwmarrin/discordgo" + "layeh.com/gumble/gumble" ) func ready(s *discordgo.Session, event *discordgo.Ready) { @@ -192,3 +193,13 @@ func voiceUpdate(s *discordgo.Session, event *discordgo.VoiceStateUpdate) { } return } + +func mumbleConnect(e *gumble.ConnectEvent) { + if BridgeConf.MumbleChannel != "" { + //join specified channel + startingChannel := e.Client.Channels.Find(BridgeConf.MumbleChannel) + if startingChannel != nil { + e.Client.Self.Move(startingChannel) + } + } +} diff --git a/main.go b/main.go index 03b32f9..10dad71 100644 --- a/main.go +++ b/main.go @@ -91,6 +91,7 @@ func main() { config.Password = *mumblePassword config.AudioInterval = time.Millisecond * 10 + // Bridge setup BridgeConf = &BridgeConfig{ Config: config, MumbleAddr: *mumbleAddr + ":" + strconv.Itoa(*mumblePort),