|
||
---|---|---|
.. | ||
codegen | ||
.gitignore | ||
.travis.yml | ||
client_connection.go | ||
client_events.go | ||
client_requests.go | ||
client_test.go | ||
client.go | ||
doc.go | ||
event_utils.go | ||
events_general.go | ||
events_other.go | ||
events_profiles.go | ||
events_recording.go | ||
events_replay_buffer.go | ||
events_scenes.go | ||
events_sources.go | ||
events_streaming.go | ||
events_studio_mode.go | ||
events_transitions.go | ||
events.go | ||
go.sum | ||
LICENSE | ||
logger.go | ||
README.md | ||
requests_general.go | ||
requests_profiles.go | ||
requests_recording.go | ||
requests_replay_buffer.go | ||
requests_scene_collections.go | ||
requests_scene_items.go | ||
requests_scenes.go | ||
requests_sources.go | ||
requests_streaming.go | ||
requests_studio_mode.go | ||
requests_transitions.go | ||
requests.go |
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() {
// Connect a client.
c := obsws.Client{Host: "localhost", Port: 4444}
if err := c.Connect(); err != nil {
log.Fatal(err)
}
defer c.Disconnect()
// Send and receive a request asynchronously.
req := obsws.NewGetStreamingStatusRequest()
if err := req.Send(c); err != nil {
log.Fatal(err)
}
// This will block until the response comes (potentially forever).
resp, err := req.Receive()
if err != nil {
log.Fatal(err)
}
log.Println("streaming:", resp.Streaming)
// Set the amount of time we can wait for a response.
obsws.SetReceiveTimeout(time.Second * 2)
// Send and receive a request synchronously.
req = obsws.NewGetStreamingStatusRequest()
// Note that we create a new request,
// because requests have IDs that must be unique.
// This will block for up to two seconds, since we set a timeout.
resp, err = req.SendReceive(c)
if err != nil {
log.Fatal(err)
}
log.Println("streaming:", resp.Streaming)
// Respond to events by registering handlers.
c.AddEventHandler("SwitchScenes", func(e obsws.Event) {
// Make sure to assert the actual event type.
log.Println("new scene:", e.(obsws.SwitchScenesEvent).SceneName)
})
time.Sleep(time.Second * 10)
}