# README
goobs
It's a Go client for obsproject/obs-websocket, allowing us to interact with OBS Studio from Go!
installation
To add this library to your module, simply go get
it like any other Go module
after you've initialized your own:
❯ go mod init blah
❯ go get github.com/onfield/goobs
usage
Here's a basic example, where we grab the version and print out the scenes. Check out the examples for more.
package main
import (
"fmt"
"log"
"github.com/onfield/goobs"
)
func main() {
client, err := goobs.New("localhost:4455", goobs.WithPassword("goodpassword"))
if err != nil {
log.Fatal(err)
}
defer client.Disconnect()
version, err := client.General.GetVersion()
if err != nil {
log.Fatal(err)
}
fmt.Printf("OBS Studio version: %s\n", version.ObsVersion)
fmt.Printf("Websocket server version: %s\n", version.ObsWebSocketVersion)
resp, _ := client.Scenes.GetSceneList()
for _, v := range resp.Scenes {
fmt.Printf("%2d %s\n", v.SceneIndex, v.SceneName)
}
}
This outputs the following:
❯ go run examples/basic/main.go
OBS Studio version: 29.0.0
Websocket server version: 5.1.0
1 Just Chatting
2 Intermission
3 Be Right Back 2
4 Be Right Back
5 Stream Starting Soon
6 Background
7 Camera Secondary
8 Camera Primary
9 Main 2
10 Main
logging
Further, we can view what this library is doing under the hood (i.e. the raw
messages it sends and receives) by setting GOOBS_LOG=debug
. This value can be
set to the typical Log4j values (e.g. debug
, info
, error
) for more or less
verbosity.
# Functions
New creates and configures a client to interact with the OBS websockets server.
WithDialer sets the underlying Gorilla WebSocket Dialer (see https://pkg.go.dev/github.com/gorilla/websocket#Dialer), should one want to customize things like the handshake timeout or TLS configuration.
WithEventSubscriptions specifies the events we'd like to susbcribe to via `client.Listen()`.
WithLogger sets the logger this library will use.
WithPassword sets the password of a client.
WithRequestHeader sets custom headers our client can send when trying to connect to the WebSockets server, allowing us specify the origin, subprotocols, or the user agent.
WithResponseTimeout sets the time we're willing to wait to receive a response from the server for any request, before responding with an error.
# Type aliases
Option represents a functional option of a Client.