update due to gumble API changes
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package barnard
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
|
||||
"github.com/layeh/barnard/uiterm"
|
||||
"github.com/layeh/gumble/gumble"
|
||||
"github.com/layeh/gumble/gumbleopenal"
|
||||
@@ -10,6 +12,9 @@ type Barnard struct {
|
||||
Config *gumble.Config
|
||||
Client *gumble.Client
|
||||
|
||||
Address string
|
||||
TLSConfig tls.Config
|
||||
|
||||
Stream *gumbleopenal.Stream
|
||||
|
||||
Ui *uiterm.Ui
|
||||
|
||||
47
client.go
47
client.go
@@ -2,11 +2,40 @@ package barnard
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"github.com/layeh/gumble/gumble"
|
||||
"github.com/layeh/gumble/gumbleopenal"
|
||||
"github.com/layeh/gumble/gumbleutil"
|
||||
)
|
||||
|
||||
func (b *Barnard) start() {
|
||||
b.Config.Attach(gumbleutil.AutoBitrate)
|
||||
b.Config.Attach(b)
|
||||
|
||||
var err error
|
||||
_, err = gumble.DialWithDialer(new(net.Dialer), b.Address, b.Config, &b.TLSConfig)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Audio
|
||||
if os.Getenv("ALSOFT_LOGLEVEL") == "" {
|
||||
os.Setenv("ALSOFT_LOGLEVEL", "0")
|
||||
}
|
||||
if stream, err := gumbleopenal.New(b.Client); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
b.Stream = stream
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Barnard) OnConnect(e *gumble.ConnectEvent) {
|
||||
b.Client = e.Client
|
||||
|
||||
b.Ui.SetActive(uiViewInput)
|
||||
b.UiTree.Rebuild()
|
||||
b.Ui.Refresh()
|
||||
@@ -23,24 +52,6 @@ func (b *Barnard) OnDisconnect(e *gumble.DisconnectEvent) {
|
||||
switch e.Type {
|
||||
case gumble.DisconnectError:
|
||||
reason = "connection error"
|
||||
case gumble.DisconnectOther:
|
||||
reason = e.String
|
||||
case gumble.DisconnectVersion:
|
||||
reason = "invalid version number"
|
||||
case gumble.DisconnectUserName:
|
||||
reason = "invalid user name"
|
||||
case gumble.DisconnectUserCredentials:
|
||||
reason = "incorrect user password/certificate"
|
||||
case gumble.DisconnectServerPassword:
|
||||
reason = "incorrect server password"
|
||||
case gumble.DisconnectUsernameInUse:
|
||||
reason = "user name in use"
|
||||
case gumble.DisconnectServerFull:
|
||||
reason = "server full"
|
||||
case gumble.DisconnectNoCertificate:
|
||||
reason = "missing certificate"
|
||||
case gumble.DisconnectAuthenticatorFail:
|
||||
reason = "authenticator verification failed"
|
||||
}
|
||||
if reason == "" {
|
||||
b.AddOutputLine("Disconnected")
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"github.com/layeh/barnard"
|
||||
"github.com/layeh/barnard/uiterm"
|
||||
"github.com/layeh/gumble/gumble"
|
||||
"github.com/layeh/gumble/gumbleutil"
|
||||
"github.com/layeh/gumble/gumbleopenal"
|
||||
_ "github.com/layeh/gumble/opus"
|
||||
)
|
||||
|
||||
@@ -24,43 +22,25 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
// Initialize
|
||||
b := barnard.Barnard{}
|
||||
b.Ui = uiterm.New(&b)
|
||||
b := barnard.Barnard{
|
||||
Config: gumble.NewConfig(),
|
||||
Address: *server,
|
||||
}
|
||||
|
||||
// Gumble
|
||||
b.Config = gumble.NewConfig()
|
||||
b.Config.Username = *username
|
||||
b.Config.Address = *server
|
||||
|
||||
if *insecure {
|
||||
b.Config.TLSConfig.InsecureSkipVerify = true
|
||||
b.TLSConfig.InsecureSkipVerify = true
|
||||
}
|
||||
if *certificate != "" {
|
||||
if cert, err := tls.LoadX509KeyPair(*certificate, *certificate); err != nil {
|
||||
cert, err := tls.LoadX509KeyPair(*certificate, *certificate)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
b.Config.TLSConfig.Certificates = []tls.Certificate{cert}
|
||||
}
|
||||
b.TLSConfig.Certificates = append(b.TLSConfig.Certificates, cert)
|
||||
}
|
||||
|
||||
b.Client = gumble.NewClient(b.Config)
|
||||
b.Client.Attach(gumbleutil.AutoBitrate)
|
||||
b.Client.Attach(&b)
|
||||
// Audio
|
||||
if os.Getenv("ALSOFT_LOGLEVEL") == "" {
|
||||
os.Setenv("ALSOFT_LOGLEVEL", "0")
|
||||
}
|
||||
if stream, err := gumbleopenal.New(b.Client); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
b.Stream = stream
|
||||
}
|
||||
|
||||
if err := b.Client.Connect(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
b.Ui = uiterm.New(&b)
|
||||
b.Ui.Run()
|
||||
}
|
||||
|
||||
2
ui.go
2
ui.go
@@ -156,6 +156,8 @@ func (b *Barnard) OnUiInitialize(ui *uiterm.Ui) {
|
||||
b.Ui.AddKeyListener(b.OnScrollOutputDown, uiterm.KeyPgdn)
|
||||
b.Ui.AddKeyListener(b.OnScrollOutputTop, uiterm.KeyHome)
|
||||
b.Ui.AddKeyListener(b.OnScrollOutputBottom, uiterm.KeyEnd)
|
||||
|
||||
b.start()
|
||||
}
|
||||
|
||||
func (b *Barnard) OnUiResize(ui *uiterm.Ui, width, height int) {
|
||||
|
||||
@@ -38,6 +38,10 @@ func (b *Barnard) TreeItemSelect(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm.T
|
||||
}
|
||||
|
||||
func (b *Barnard) TreeItem(item uiterm.TreeItem) []uiterm.TreeItem {
|
||||
if b.Client == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var treeItem TreeItem
|
||||
if ti, ok := item.(TreeItem); !ok {
|
||||
root := b.Client.Channels[0]
|
||||
|
||||
Reference in New Issue
Block a user