goobs

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2021 License: Apache-2.0 Imports: 20 Imported by: 34

README

goobs

Go Reference

It's a Go client for Palakis/obs-websocket, allowing us to interact with OBS Studio via Go.

disclaimer

This project is still a work-in-progress.

It's currently using v4.5.0 of the protocol.

usage

Here's the contents of examples/sources.go. For brevity, we skip error checking:

package main

import (
	"fmt"
	"log"

	"github.com/andreykaipov/goobs"
	"github.com/andreykaipov/goobs/api/events"
	"github.com/andreykaipov/goobs/api/requests/sources"
)

var localhost = "172.24.80.1" // you'll likely have to change this :)

func main() {
	client, err := goobs.New(localhost+":4444", goobs.WithPassword("hello"))
	if err != nil {
		panic(err)
	}
	defer client.Disconnect()

	version, _ := client.General.GetVersion()
	fmt.Printf("Websocket server version: %s\n", version.ObsWebsocketVersion)
	fmt.Printf("OBS Studio version: %s\n", version.ObsStudioVersion)

	go func() {
		for event := range client.IncomingEvents {
			switch e := event.(type) {
			case *events.TransitionBegin:
				log.Printf("Transition the scene: %#v", e)
			case *events.Error:
				log.Printf("Got an error: %s", e.Err)
			default:
				log.Printf("Unhandled event: %#v", e.GetUpdateType())
			}
		}
	}()

	list, _ := client.Sources.GetSourcesList()

	fmt.Println("Available sources:")
	for _, v := range list.Sources {
		fmt.Printf("- %-25s of type %s\n", v.Name, v.TypeId)
	}

	update := func(volume float64) {
		da := "Desktop Audio"
		client.Sources.SetVolume(&sources.SetVolumeParams{
			Source: da,
			Volume: volume,
		})
		volumeResp, _ := client.Sources.GetVolume(&sources.GetVolumeParams{Source: da})
		fmt.Printf("Now %q is at %.3f\n", da, volumeResp.Volume)
	}

	update(0.3)
	update(0.5)
}

And the corresponding output:

❯ go run examples/sources.go
2021/05/29 15:32:07 connecting to ws://172.24.80.1:4444
Websocket server version: 4.9.0
OBS Studio version: 26.1.1
Available sources:
- Video Capture Device      of type dshow_input
- Audio Output Capture      of type wasapi_output_capture
- Window Capture            of type window_capture
- Chat                      of type browser_source
- Mic/Aux                   of type wasapi_input_capture
- Desktop Audio             of type wasapi_output_capture
2021/05/29 15:32:07 Unhandled event: "SourceVolumeChanged"
Now "Desktop Audio" is at 0.300
2021/05/29 15:32:07 Unhandled event: "SourceVolumeChanged"
Now "Desktop Audio" is at 0.500

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// IncomingEvents is used to read events from OBS. For example,
	//
	// “`go
	// for event := range client.IncomingEvents {
	// 	switch e := event.(type) {
	// 	case *events.SomeEventA:
	// 		...
	// 	case *events.SomeEventB:
	// 		...
	// 	default:
	// 	}
	// }
	// “`
	IncomingEvents chan events.Event

	*requests.Client
	// contains filtered or unexported fields
}

Client represents a client to an OBS websockets server.

func New

func New(host string, opts ...Option) (*Client, error)

New creates and configures a client to interact with the OBS websockets server. It also opens up a connection, so be sure to check the error.

type Option

type Option func(*Client)

Option represents a functional option of a Client.

func WithPassword

func WithPassword(x string) Option

WithPassword sets the password of a client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL