Go client for an OBS WebSockets server

Overview

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
Issues
  • Expose internal structs

    Expose internal structs

    Great work on this!

    The only issue I'm currently facing is accessing nested structs like Font in SetTextFreetype2PropertiesParams. Since the struct isn't a proper type, it's a bit awkward to first initialize the parent in order to access the nested struct.

    Do you think we could improve the generator here?

    opened by muesli 8
  • Example / README aren't up-to-date anymore

    Example / README aren't up-to-date anymore

    Looks like the API diverged from the example.

    opened by muesli 5
  • Add Go build/test workflow

    Add Go build/test workflow

    Adds two GitHub Action workflow that run for every push and pull request.

    The first one tries to build the entire project on Ubuntu, macOS, and Windows for Go 1.11 (minimum required version) as well as the latest available Go version (at the time of the action being run). It will also run go test should we have test cases in the future. Currently it will just silently pass as it doesn't find any.

    The second one runs the generator (make generate) on Ubuntu and tries to build the project with the freshly generated sources.

    opened by muesli 2
  • Feature/omitempty

    Feature/omitempty

    opened by andreykaipov 2
  • Remove log call

    Remove log call

    This being a library we should prevent logging (per default). Since this is the only log call currently I've decided to simply comment it out. If we want to use a logger, we need to provide a way for the library's user to overwrite the logger.

    opened by muesli 1
  • CI

    CI

    Since most of the code is generated, unit tests don't feel too practical.

    I'd like to write a few e2e examples and run them against a Dockerized obs-studio and websocket server as our test suite.

    Sounds pretty silly since there's no UI, but I should be able to export my settings locally and import them into the image. I've gotten both built and running, but haven't yet tried connecting and running the existing examples against it.

    opened by andreykaipov 1
  • Generated structs should have the `omitempty` tag option

    Generated structs should have the `omitempty` tag option

    Would avoid situations like this described in https://github.com/andreykaipov/goobs/pull/5#discussion_r652210713

    opened by andreykaipov 1
  • Feature/anonymous structs

    Feature/anonymous structs

    opened by andreykaipov 1
  • Feature/future proofing

    Feature/future proofing

    opened by andreykaipov 1
  • Feature/godoc for category clients

    Feature/godoc for category clients

    null

    opened by andreykaipov 0
Releases(v0.7.1)
  • v0.7.1(Aug 29, 2021)

  • v0.7.0(Aug 29, 2021)

    new feature:

    • configurable debug logging, see new options WithDebug(bool) and WithLogger(requests.Logger) (#20)

    maintenance things:

    • CI stuff and e2e tests (#17, #18)
    • documentation stuff (#19, #21)
    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(Jun 20, 2021)

    Changes:

    • Nested anonymous structs are now declared as their own structs, e.g. Font, Scale, StreamSettings, etc. (https://github.com/andreykaipov/goobs/issues/8)
    • Many fields now have the omitempty JSON tag option (https://github.com/andreykaipov/goobs/issues/12) by default

    Thank you to @muesli for helping me test out this library!

    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Jun 14, 2021)

Owner
Andrey Kaipov
Hello!
Andrey Kaipov
Simple example for using Turbos Streams in Go with the Gorilla WebSocket toolkit.

Go Example for TurboStreams over WebSockets Simple example for using Turbos Streams in Go with the Gorilla WebSocket toolkit.

Jan Stamer 16 Jun 29, 2021
Turn any program that uses STDIN/STDOUT into a WebSocket server. Like inetd, but for WebSockets.

websocketd websocketd is a small command-line tool that will wrap an existing command-line interface program, and allow it to be accessed via a WebSoc

Joe Walnes 15.7k Sep 14, 2021
WebSocket for fasthttp

websocket WebSocket library for fasthttp and net/http. Checkout examples to inspire yourself. Install go get github.com/dgrr/websocket Why another Web

Darío 14 Aug 6, 2021
a simple shitty project for learn more about websockets

video-transmission A simple shitty project for learn more about websockets. For run this you only need to have docker in your computer and then execut

ranon rat 5 Jul 14, 2021
Minimal and idiomatic WebSocket library for Go

websocket websocket is a minimal and idiomatic WebSocket library for Go. Install go get nhooyr.io/websocket Highlights Minimal and idiomatic API First

Anmol Sethi 1.9k Sep 3, 2021
Chat bots (& more) for Zoom by figuring out their websocket protocol

zoomer - Bot library for Zoom meetings Good bot support is part of what makes Discord so nice to use. Unfortunately, the official Zoom API is basicall

Christopher Tarry 41 Sep 2, 2021
:notes: Minimalist websocket framework for Go

melody ?? Minimalist websocket framework for Go. Melody is websocket framework based on github.com/gorilla/websocket that abstracts away the tedious p

Ola 2.2k Sep 5, 2021
proxy your traffic through CDN using websocket

go-cdn2proxy proxy your traffic through CDN using websocket what does it do example server client thanks what does it do you can use this as a library

jm33-ng 31 Sep 9, 2021
Terminal on browser via websocket

Terminal on browser via websocket. Supportted OS Linux Mac

skanehira 122 Aug 27, 2021
A fast, well-tested and widely used WebSocket implementation for Go.

Gorilla WebSocket Gorilla WebSocket is a Go implementation of the WebSocket protocol. Documentation API Reference Chat example Command example Client

Gorilla Web Toolkit 15.4k Sep 7, 2021
WebSocket Command Line Client written in Go

ws-cli WebSocket Command Line Client written in Go Installation go get github.com/kseo/ws-cli Usage $ ws-cli -url ws://echo.websocket.org connected (

Kwang Yul Seo 16 Jun 13, 2021
websocket消息推送服务

balloons-websocket 用于构建实时应用程序的基础架构和API,balloons提供了最好的基础架构和API,以大规模地提供实时体验。向最终用户提供快速稳定的实时消息。让我们处理实时消息传递的复杂性,以便您可以专注于代码。 balloons的实时API向开发人员公开了整个balloon

null 11 Apr 4, 2021
Tiny WebSocket library for Go.

RFC6455 WebSocket implementation in Go.

Sergey Kamardin 4.1k Sep 11, 2021
go-socket.io is library an implementation of Socket.IO in Golang

go-socket.io is library an implementation of Socket.IO in Golang, which is a realtime application framework.

Googol Lee 4.3k Sep 14, 2021