-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.go
67 lines (56 loc) · 1.58 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
package main
import (
"log"
"math/rand"
"os"
"time"
"github.com/andreykaipov/goobs"
"github.com/andreykaipov/goobs/api/events"
"github.com/andreykaipov/goobs/api/requests/inputs"
)
func green(f string, v ...any) { log.Printf("\033[32m"+f+"\033[0m", v...) }
func blue(f string, v ...any) { log.Printf("\033[34m"+f+"\033[0m", v...) }
func main() {
client, err := goobs.New("localhost:4455", goobs.WithPassword("goodpassword"))
if err != nil {
log.Fatal(err)
}
defer client.Disconnect()
go client.Listen(func(event any) {
switch e := event.(type) {
case *events.InputVolumeChanged:
green("%s's volume is now %f", e.InputName, e.InputVolumeDb)
case *events.ExitStarted:
green("Gracefully shutting down")
green("Bye")
os.Exit(0)
default:
blue("Unhandled: %#v", e)
}
})
rand.Seed(time.Now().UnixNano())
list, _ := client.Inputs.GetInputList()
for _, v := range list.Inputs {
name := v.InputName
// we can use a builder pattern...
params := inputs.NewSetInputVolumeParams().
WithInputName(name).
WithInputVolumeMul(rand.Float64())
if _, err := client.Inputs.SetInputVolume(params); err != nil {
blue("%s doesn't support audio: %s", name, err)
continue
}
// ...or we can set the fields directly
volume := rand.Float64()
if _, err := client.Inputs.SetInputVolume(&inputs.SetInputVolumeParams{
InputName: &name,
InputVolumeMul: &volume,
}); err != nil {
blue("%s doesn't support audio: %s", name, err)
continue
}
}
// play around in OBS and maybe close it - observe the events it sends
//
time.Sleep(30 * time.Second)
}