]> git.0d.be Git - barnard.git/blob - cmd/barnard/main.go
fix broken audio
[barnard.git] / cmd / barnard / main.go
1 package main
2
3 import (
4         "crypto/tls"
5         "flag"
6         "fmt"
7         "os"
8
9         "github.com/layeh/barnard"
10         "github.com/layeh/barnard/uiterm"
11         "github.com/layeh/gumble/gumble"
12         "github.com/layeh/gumble/gumbleutil"
13         "github.com/layeh/gumble/gumble_openal"
14         _ "github.com/layeh/gumble/opus"
15 )
16
17 func main() {
18         // Command line flags
19         server := flag.String("server", "localhost:64738", "the server to connect to")
20         username := flag.String("username", "", "the username of the client")
21         insecure := flag.Bool("insecure", false, "skip server certificate verification")
22         certificate := flag.String("certificate", "", "PEM encoded certificate and private key")
23
24         flag.Parse()
25
26         // Initialize
27         b := barnard.Barnard{}
28         b.Ui = uiterm.New(&b)
29
30         // Gumble
31         b.Config = gumble.NewConfig()
32         b.Config.Username = *username
33         b.Config.Address = *server
34         if *insecure {
35                 b.Config.TLSConfig.InsecureSkipVerify = true
36         }
37         if *certificate != "" {
38                 if cert, err := tls.LoadX509KeyPair(*certificate, *certificate); err != nil {
39                         fmt.Fprintf(os.Stderr, "%s\n", err)
40                         os.Exit(1)
41                 } else {
42                         b.Config.TLSConfig.Certificates = []tls.Certificate{cert}
43                 }
44         }
45
46         b.Client = gumble.NewClient(b.Config)
47         b.Client.Attach(gumbleutil.AutoBitrate)
48         b.Client.Attach(&b)
49         // Audio
50         if os.Getenv("ALSOFT_LOGLEVEL") == "" {
51                 os.Setenv("ALSOFT_LOGLEVEL", "0")
52         }
53         if stream, err := gumble_openal.New(b.Client); err != nil {
54                 fmt.Fprintf(os.Stderr, "%s\n", err)
55                 os.Exit(1)
56         } else {
57                 b.Stream = stream
58         }
59
60         if err := b.Client.Connect(); err != nil {
61                 fmt.Fprintf(os.Stderr, "%s\n", err)
62                 os.Exit(1)
63         }
64
65         b.Ui.Run()
66 }