begin switching to mumble event listeners

This commit is contained in:
stryan 2021-01-05 13:16:03 -05:00
parent bf166f7a9c
commit c469a65ed6
3 changed files with 17 additions and 8 deletions

View File

@ -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)

View File

@ -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)
}
}
}

View File

@ -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),