obsws
obsws
provides client functionality for obs-websocket
.
Currently, the target version is 4.4
.
Installation
go get github.com/christopher-dG/go-obs-websocket
Usage
package main
import (
"log"
"time"
"github.com/christopher-dG/go-obs-websocket"
)
func main() {
c := obsws.Client{Host: "localhost", Port: 4444}
if err := c.Connect(); err != nil {
log.Fatal(err)
}
defer c.Disconnect()
req := obsws.NewGetStreamingStatusRequest()
if err := req.Send(c); err != nil {
log.Fatal(err)
}
resp, err := req.Receive()
if err != nil {
log.Fatal(err)
}
log.Println("streaming:", resp.Streaming)
obsws.SetReceiveTimeout(time.Second * 2)
req = obsws.NewGetStreamingStatusRequest()
resp, err = req.SendReceive(c)
if err != nil {
log.Fatal(err)
}
log.Println("streaming:", resp.Streaming)
c.AddEventHandler("SwitchScenes", func(e obsws.Event) {
log.Println("new scene:", e.(obsws.SwitchScenesEvent).SceneName)
})
time.Sleep(time.Second * 10)
}