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
|
package main
import (
"fmt"
"log"
"math/rand"
"os"
"time"
"github.com/andreykaipov/goobs"
"github.com/andreykaipov/goobs/api/events"
"github.com/andreykaipov/goobs/api/requests/sources"
)
func main() {
client, err := goobs.New(
os.Getenv("WSL_HOST")+":4444",
goobs.WithPassword("hello"), // optional
goobs.WithDebug(os.Getenv("OBS_DEBUG") != ""), // optional
)
if err != nil {
panic(err)
}
go func() {
for event := range client.IncomingEvents {
switch e := event.(type) {
case *events.SourceVolumeChanged:
fmt.Printf("Volume changed for %-25q: %f\n", e.SourceName, e.Volume)
default:
log.Printf("Unhandled event: %#v", e.GetUpdateType())
}
}
}()
fmt.Println("Setting random volumes for each source...")
rand.Seed(time.Now().UnixNano())
list, _ := client.Sources.GetSourcesList()
for _, v := range list.Sources {
if _, err := client.Sources.SetVolume(&sources.SetVolumeParams{
Source: v.Name,
Volume: rand.Float64(),
}); err != nil {
panic(err)
}
}
if len(list.Sources) == 0 {
fmt.Println("No sources!")
os.Exit(0)
}
fmt.Println("Test toggling the mute status of the first source...")
name := list.Sources[0].Name
resp, _ := client.Sources.GetVolume(&sources.GetVolumeParams{Source: name})
fmt.Printf("%s is muted? %t\n", name, resp.Muted)
_, _ = client.Sources.ToggleMute(&sources.ToggleMuteParams{Source: name})
resp, _ = client.Sources.GetVolume(&sources.GetVolumeParams{Source: name})
fmt.Printf("%s is muted? %t\n", name, resp.Muted)
}
|