This repository has been archived by the owner on May 8, 2024. It is now read-only.
forked from lornajane/streamdeck-tricks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
86 lines (68 loc) · 2.23 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"net/http"
"sync"
streamdeck "github.com/magicmonkey/go-streamdeck"
_ "github.com/magicmonkey/go-streamdeck/devices"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/zyebytevt/starburst-go/subsystems/dbus"
"github.com/zyebytevt/starburst-go/subsystems/general"
"github.com/zyebytevt/starburst-go/subsystems/obs"
"github.com/zyebytevt/starburst-go/subsystems/twitch"
"github.com/zyebytevt/starburst-go/subsystems/vseeface"
)
var sd *streamdeck.StreamDeck
func loadConfigAndDefaults() {
// first set some default values
viper.AddConfigPath(".")
viper.SetDefault("obs.host", "localhost") // OBS webhooks endpoint
viper.SetDefault("obs.port", 4455) // OBS webhooks endpoint
// now read in config for any overrides
err := viper.ReadInConfig()
if err != nil { // Handle errors reading the config file
logrus.WithError(err).Warning("Could not read config file.")
}
}
func main() {
loadConfigAndDefaults()
logrus.Info("StarBurst, Go! ZyeByte sends her regards.")
var err error
sd, err = streamdeck.New()
if err != nil {
logrus.WithError(err).Error("Could not connect to the StreamDeck. Please check connectivity.")
panic(err)
}
if err := general.Setup(sd); err != nil {
logrus.WithError(err).Error("Failed to initialize general functionality.")
panic(err)
}
if err := dbus.Setup(sd); err != nil {
logrus.WithError(err).Warning("Failed to initialize D-Bus addon.")
}
if err := vseeface.Setup(sd); err != nil {
logrus.WithError(err).Warning("Failed to initialize VSeeFace addon.")
}
if err := obs.Setup(sd); err != nil {
logrus.WithError(err).Warning("Failed to initialize OBS addon.")
}
if err := twitch.Setup(sd); err != nil {
logrus.WithError(err).Warning("Failed to initialize Twitch addon.")
}
// TODO: Do we need to have this webserver running at all times? Maybe just
// for authentication is enough.
go webserver()
logrus.Info("Up and running!")
var wg sync.WaitGroup
wg.Add(1)
wg.Wait()
}
func webserver() {
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "OK")
})
http.HandleFunc("/auth-callback", twitch.HandleAuthCallback)
logrus.Info("Starting up webserver...")
http.ListenAndServe(":7001", nil)
}