afriza / goobs

Go client library to control OBS Studio via WebSockets.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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, 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

advanced configuration

  • GOOBS_LOG can be set to debug, info, or error to better understand what our client is doing under the hood.

  • GOOBS_PROFILE can be set to enable profiling. For example, the following will help us find unreleased memory:

    GOOBS_PROFILE=memprofile=mem.out OBS_PORT=4455 go test -v -run=profile client_test.gogo tool pprof -top -sample_index=inuse_space mem.out

    Set GOOBS_PROFILE=help to see all the other available options.

About

Go client library to control OBS Studio via WebSockets.

License:Apache License 2.0


Languages

Language:Go 98.0%Language:Shell 1.1%Language:Makefile 0.5%Language:Dockerfile 0.4%