/goobs

Go client library to control OBS Studio via WebSockets.

Primary LanguageGoApache License 2.0Apache-2.0

goobs

Protocol Version Documentation Build Status Go Report

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 blahgo get github.com/andreykaipov/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/andreykaipov/goobs"
)

func main() {
	client, err := goobs.New("localhost:4455", goobs.WithPassword("goodpassword"))
	if err != nil {
		log.Fatal(err)
	}
	defer client.Disconnect()

	version, _ := client.General.GetVersion()
	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: 27.2.4
Websocket server version: 5.0.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.