streamdeck-obs-replay/obsws
Tyler eca3834fd7
continuous-integration/drone/push Build is failing Details
initial version
2020-01-14 23:32:53 -05:00
..
codegen initial version 2020-01-14 23:32:53 -05:00
.gitignore initial version 2020-01-14 23:32:53 -05:00
.travis.yml initial version 2020-01-14 23:32:53 -05:00
LICENSE initial version 2020-01-14 23:32:53 -05:00
README.md initial version 2020-01-14 23:32:53 -05:00
client.go initial version 2020-01-14 23:32:53 -05:00
client_connection.go initial version 2020-01-14 23:32:53 -05:00
client_events.go initial version 2020-01-14 23:32:53 -05:00
client_requests.go initial version 2020-01-14 23:32:53 -05:00
client_test.go initial version 2020-01-14 23:32:53 -05:00
doc.go initial version 2020-01-14 23:32:53 -05:00
event_utils.go initial version 2020-01-14 23:32:53 -05:00
events.go initial version 2020-01-14 23:32:53 -05:00
events_general.go initial version 2020-01-14 23:32:53 -05:00
events_other.go initial version 2020-01-14 23:32:53 -05:00
events_profiles.go initial version 2020-01-14 23:32:53 -05:00
events_recording.go initial version 2020-01-14 23:32:53 -05:00
events_replay_buffer.go initial version 2020-01-14 23:32:53 -05:00
events_scenes.go initial version 2020-01-14 23:32:53 -05:00
events_sources.go initial version 2020-01-14 23:32:53 -05:00
events_streaming.go initial version 2020-01-14 23:32:53 -05:00
events_studio_mode.go initial version 2020-01-14 23:32:53 -05:00
events_transitions.go initial version 2020-01-14 23:32:53 -05:00
go.sum initial version 2020-01-14 23:32:53 -05:00
logger.go initial version 2020-01-14 23:32:53 -05:00
requests.go initial version 2020-01-14 23:32:53 -05:00
requests_general.go initial version 2020-01-14 23:32:53 -05:00
requests_profiles.go initial version 2020-01-14 23:32:53 -05:00
requests_recording.go initial version 2020-01-14 23:32:53 -05:00
requests_replay_buffer.go initial version 2020-01-14 23:32:53 -05:00
requests_scene_collections.go initial version 2020-01-14 23:32:53 -05:00
requests_scene_items.go initial version 2020-01-14 23:32:53 -05:00
requests_scenes.go initial version 2020-01-14 23:32:53 -05:00
requests_sources.go initial version 2020-01-14 23:32:53 -05:00
requests_streaming.go initial version 2020-01-14 23:32:53 -05:00
requests_studio_mode.go initial version 2020-01-14 23:32:53 -05:00
requests_transitions.go initial version 2020-01-14 23:32:53 -05:00

README.md

obsws

Build Status GoDoc

obsws provides client functionality for obs-websocket. Currently, the target version is 4.4.

Installation

go get github.com/christopher-dG/go-obs-websocket

Usage

package main

import (
	"log"
	"time"

	"github.com/christopher-dG/go-obs-websocket"
)

func main() {
	// Connect a client.
	c := obsws.Client{Host: "localhost", Port: 4444}
	if err := c.Connect(); err != nil {
		log.Fatal(err)
	}
	defer c.Disconnect()

	// Send and receive a request asynchronously.
	req := obsws.NewGetStreamingStatusRequest()
	if err := req.Send(c); err != nil {
		log.Fatal(err)
	}
	// This will block until the response comes (potentially forever).
	resp, err := req.Receive()
	if err != nil {
		log.Fatal(err)
	}
	log.Println("streaming:", resp.Streaming)

	// Set the amount of time we can wait for a response.
	obsws.SetReceiveTimeout(time.Second * 2)

	// Send and receive a request synchronously.
	req = obsws.NewGetStreamingStatusRequest()
	// Note that we create a new request,
	// because requests have IDs that must be unique.
	// This will block for up to two seconds, since we set a timeout.
	resp, err = req.SendReceive(c)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("streaming:", resp.Streaming)

	// Respond to events by registering handlers.
	c.AddEventHandler("SwitchScenes", func(e obsws.Event) {
		// Make sure to assert the actual event type.
		log.Println("new scene:", e.(obsws.SwitchScenesEvent).SceneName)
	})

	time.Sleep(time.Second * 10)
}