Go client for an OBS WebSockets server

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
Owner
Comments
  • 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?

  • Make API values optional

    Make API values optional

    It would be nice if values like SetSceneItemPropertiesParams's Locked or Rotation were pointers to their values, making setting them optional. Currently forgetting to set that member value will essentially reset the Locked status or Rotation.

    The biggest risk I see here is that newer versions of the OBS Websockets API and this library will introduce new member values. Bumping the goobs dependency (e.g. in obs-cli) is a bit risky then, as any unhandled member values could potentially cause unexpected behavior.

    See: https://github.com/muesli/obs-cli/issues/34

  • Please drop vendored libraries

    Please drop vendored libraries

    I packaged goobs for Debian (see https://tracker.debian.org/pkg/golang-github-andreykaipov-goobs) and had to remove the vendored libraries from the source package (internal/vendor and vendor). Since you are using go.mod can you drop the vendored libraries from the git repository?

  • Please support setting the client name and version

    Please support setting the client name and version

    Please allow users of the goobs library to set the client name and version. Otherwise it will use Go-http-client/1.1. See also https://github.com/muesli/obs-cli/issues/26

    websocket.Dial takes a requestHeader of type http.Header which could be used.

  • Websocket 5.0.*

    Websocket 5.0.*

    Hey there,

    I've noticed that there's a 5.0 branch that's been untouched since February. Are there any plans to update this project to support 5.0, or is it considered dead/unmaintained?

  • Fix panic on connection close

    Fix panic on connection close

    When the connection is closed from OBS side handleConnection() needs to stop trying to call ReadJSON(). Otherwise the underlying websocket package panics with panic: repeated read on failed websocket connection.

    I'm not completely sure if this is the right approach to handle this issue. It works pretty well for me by listening to errors and recreating the goobs instance in this case.

  • timeout waiting for authentication

    timeout waiting for authentication

    Trying to connect to OBS on Windows local network gives authentication error.

    Steps to reproduce:

    1. Configure ethernet on windows to be private and open port 4444 (not 4455 from tutorial)
    2. Configure OBS 27.2.4 with obs-websockets 4.9.1-compat
    3. Follow the "Here's a basic example" tutorial
    4. Run program

    The OBS log will show connection is established (meaning it is not a firewall issue)

    11:59:21.137: [obs-websocket 4.9.1-compat] new client connection from 192.168.1.3:38014
    11:59:31.146: [obs-websocket 4.9.1-compat] Websocket connection with client '192.168.1.3:38014' closed (disconnected). Code is 1006, reason is: 'End of File'
    

    The program exits with:

    2022/08/14 18:53:19 timeout waiting for authentication: 10000ms
    exit status 1
    

    I re-entered the OBS websocket password several times to ensure it's not a typo in the password.

  • v5

    v5

    obs-websocket has not officially released v5 yet, but https://github.com/obsproject/obs-websocket/pull/863 to overhaul the documentation has been merged in and the new generated protocol can be found at https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.json.

    Although v5 still in development, I think it's possible to start tinkering around with parsing the v5 protocol json. I haven't taken a close look, but it's very likely just rewriting it from scratch would be much cleaner than trying to mold the existing code... as a lot of it is very different to v4.9.

  • 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.

  • obs websocket v5.1.0

    obs websocket v5.1.0

    Guess there's no new stuff. Surprised there's no breaking changes!

    For posterity, release process was as follows:

    1. Bump goobs_version and obs_protocol_version in version.go
    2. Bump the versions of the links in the README.md
    3. Run make clean && make generate to pull in latest protocol changes
    4. Ensure no tests are failing via make test, modifying internal/generate/tests/main.go if necessary
    5. Double check the versions from step 1, and merge the PR in
    6. Back on the main branch, pull in the latest changes and run make release
    7. View and edit the release from the Web UI if necessary (I like to add the corresponding obs-websocket protocol version to the name of the release)
  • client: close protocol version check connection

    client: close protocol version check connection

    This change is not important. Just a small improvement.

    I noticed that obs-websocket server closes the version check connection 5 seconds after version check. Probably according to the value of timeout_close_handshake from websocketpp.

    After this change, version check connection closes immediately.

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

Mar 29, 2022
handling 1M websockets connections in Go

Going Infinite, handling 1M websockets connections in Go This repository holds the complete implementation of the examples seen in Gophercon Israel ta

Jan 1, 2023
Kucoin proxy for freqtrade that is using websockets to maintain candlestick/klines data in memory

Kucoin proxy for freqtrade that is using websockets to maintain candlestick/klines data in memory, thus having great performance and reducing the amount of API calls to the Kucoin API. All other calls are proxied as usual.

Dec 5, 2022
A small and basic service to echo requests made via websockets

Ping Service A small and basic service to echo requests made via websockets, can be useful for measuring latency between clients and this service. Run

Nov 18, 2021
Websockets - Chaotic Web Sockets With Golang

Chaotic Web Sockets The intention of this project is to show the behavior of a s

Jan 21, 2022
Awesome WebSocket CLient - an interactive command line client for testing websocket servers
Awesome WebSocket CLient - an interactive command line client for testing websocket servers

Awesome WebSocket CLient - an interactive command line client for testing websocket servers

Dec 30, 2022
BrisGolang is a Go implementation of the game of briscola using the WebSocket protocol for client/server communication.

BrisGolang BrisGolang is a Go implementation of the game of briscola using the WebSocket protocol for client/server communication. Usage You can play

Nov 1, 2021
API that upgrades connection to use websocket. Contains server and client and testing how they communicate

Websocket Test API How to execute First run server using: make run-server. Then run many client instances with: make run-client. Then start typing in

Dec 25, 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 (

Nov 12, 2021
A tiny command line websocket client written in Go

wsc A simplistic tool for sending and receiving websocket messages from a command line. Mainly useful to test websocket servers. Getting started: $ go

Jan 12, 2022
Websocket client sample integration (go) for FairOS.

fairos-websocket-client FairOS websocket clients should be an extension on the FairOS OpenAPI specification, with introduction of events for seamless

Jul 14, 2022
Client Implementation of eosio state-history websocket.

Client Implementation of eosio state-history websocket.

Dec 6, 2022
Just a PubSub Websocket Server

Eventual Agent Just a PubSub Websocket Server The eventual agent allows cluster local apps to subscribe and publish over network. Goals Provide a WebS

Dec 24, 2022
HLive is a server-side WebSocket based dynamic template-less view layer for Go.
HLive is a server-side WebSocket based dynamic template-less view layer for Go.

HLive HLive is a server-side WebSocket based dynamic template-less view layer for Go. HLive is a fantastic tool for creating complex and dynamic brows

Jan 8, 2023
Websocket server, implemented flow Room style

ignite A websocket server module. Require redis to scale to multi nodes. Client/server message follow format type Message struct { Event string

Apr 10, 2022
Websocket server. Get data from provider API, clean data and send to websoket, when it's changed.

Описание Сервис получает данные по киберспортивным матчам CS:GO от провайдера, структурирует, очищает от лишнего и отправляет всем активным вебсокет к

Apr 6, 2022
A simple server to convert ATK-IMU901 serial data into websocket stream

A simple server to convert ATK-IMU901 serial data into WebSocket stream.

Jan 31, 2022
Go client for an OBS WebSockets server

goobs 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.

Jan 1, 2023
An OBS overlay (browser source) for mumble

Mumble UI An attempt at creating an overlay that could be used inside of OBS to show who is speaking for the DAY[0] Podcast. It is meant to be reasona

Jan 27, 2022
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

Dec 31, 2022