initial version
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Tyler 2020-01-14 23:32:53 -05:00
commit eca3834fd7
53 changed files with 11473 additions and 0 deletions

39
.drone.yml Normal file
View File

@ -0,0 +1,39 @@
kind: pipeline
name: default
steps:
- name: binary
volumes:
- name: cache
path: /tmp/build
image: golang
commands:
- GOOS=windows GOARCH=amd64 go build -o /tmp/build/remote.exe
- GOOS=darwin GOARCH=amd64 go build -o /tmp/build/remote
- name: package
volumes:
- name: cache
path: /tmp/build
image: alpine:latest
commands:
- apk add --update zip jq
- cp /tmp/build/replay.exe /tmp/build/replay plugin/
- VERSION=`cat plugin/manifest.json | jq -r '.Version'`
- echo "v$VERSION" > /tmp/build/version.txt
- mv plugin tf.meow.obsreplay.sdPlugin
- zip -r /tmp/build/tf.meow.obsreplay.streamDeckPlugin tf.meow.obsreplay.sdPlugin
- name: release
volumes:
- name: cache
path: /tmp/build
image: tystuyfzand/drone-gitea-release
settings:
tag_file: /tmp/build/version.txt
title_file: /tmp/build/version.txt
files: [ '/tmp/build/tf.meow.obsreplay.streamDeckPlugin' ]
environment:
PLUGIN_API_KEY:
from_secret: gitea_token
volumes:
- name: cache
temp: {}

11
go.mod Normal file
View File

@ -0,0 +1,11 @@
module meow.tf/streamdeck/obs-replay
go 1.13
require (
github.com/christopher-dG/go-obs-websocket v0.0.0-20181224025342-2efc3605bff5
github.com/gorilla/websocket v1.4.1
github.com/mitchellh/mapstructure v1.1.2
github.com/valyala/fastjson v1.4.1
meow.tf/streamdeck/sdk v0.0.0-20190519021527-54a933f8777d
)

11
go.sum Normal file
View File

@ -0,0 +1,11 @@
github.com/christopher-dG/go-obs-websocket v0.0.0-20181224025342-2efc3605bff5 h1:VtKPsvxzKt/+EnkhcPp0Xg7MDjt/a+CNRSj5phITbjo=
github.com/christopher-dG/go-obs-websocket v0.0.0-20181224025342-2efc3605bff5/go.mod h1:hFg9UFHefvNCvpWpYtOaP/VT2HyokIJsmV1AUBjpTeQ=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/valyala/fastjson v1.4.1 h1:hrltpHpIpkaxll8QltMU8c3QZ5+qIiCL8yKqPFJI/yE=
github.com/valyala/fastjson v1.4.1/go.mod h1:nV6MsjxL2IMJQUoHDIrjEI7oLyeqK6aBD7EFWPsvP8o=
meow.tf/streamdeck/sdk v0.0.0-20190519021527-54a933f8777d h1:PPZHRoZFy9p4GjXssLvTneJfX6cS0bEm51md5TqXFgU=
meow.tf/streamdeck/sdk v0.0.0-20190519021527-54a933f8777d/go.mod h1:SnrBz5Bcdgk/wwIvgjo+3gXiBYV6b/dYSpb2AFxjHcA=

3
obsws/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
__pycache__
comments.json
protocol.md

6
obsws/.travis.yml Normal file
View File

@ -0,0 +1,6 @@
language: go
go:
- 1.10.x
- master
notifications:
email: false

19
obsws/LICENSE Normal file
View File

@ -0,0 +1,19 @@
Copyright (c) 2018 Chris de Graaf
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

69
obsws/README.md Normal file
View File

@ -0,0 +1,69 @@
# obsws
[![Build Status](https://travis-ci.com/christopher-dG/go-obs-websocket.svg?branch=master)](https://travis-ci.com/christopher-dG/go-obs-websocket)
[![GoDoc](https://godoc.org/github.com/christopher-dG/go-obs-websocket?status.svg)](https://godoc.org/github.com/christopher-dG/go-obs-websocket)
`obsws` provides client functionality for [`obs-websocket`](https://github.com/Palakis/obs-websocket).
Currently, the target version is `4.4`.
## Installation
```sh
go get github.com/christopher-dG/go-obs-websocket
```
## Usage
```go
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)
}
```

92
obsws/client.go Normal file
View File

@ -0,0 +1,92 @@
package obsws
import (
"strconv"
"sync"
"time"
"github.com/gorilla/websocket"
"github.com/mitchellh/mapstructure"
)
const bufferSize = 100
var (
receiveTimeout = time.Duration(0)
messageID = 0
lock = sync.Mutex{}
)
// Client is the interface to obs-websocket.
// Client{Host: "localhost", Port: 4444} will probably work if you haven't configured OBS.
type Client struct {
Host string // Host (probably "localhost").
Port int // Port (OBS default is 4444).
Password string // Password (OBS default is "").
conn *websocket.Conn // Underlying connection to OBS.
receiveTimeout time.Duration // Maximum blocking time for receiving request responses
connected bool // True until Disconnect is called.
handlers map[string]func(e Event) // Event handlers.
respQ chan map[string]interface{} // Queue of received responses.
}
// poll listens for responses/events.
// This function blocks until Disconnect is called.
func (c *Client) poll() {
Logger.Println("started polling")
for c.connected {
m := make(map[string]interface{})
if err := c.conn.ReadJSON(&m); err != nil {
if !c.connected {
return
}
Logger.Println("read from WS:", err)
continue
}
if _, ok := m["message-id"]; ok {
c.handleResponse(m)
} else {
c.handleEvent(m)
}
}
}
// Connected returns wheter or not the client is connected.
func (c *Client) Connected() bool {
return c.connected
}
// SetReceiveTimeout sets the maximum blocking time for receiving request responses.
// If set to 0 (the default), there is no timeout.
func SetReceiveTimeout(timeout time.Duration) {
receiveTimeout = timeout
}
// getMessageID generates a string that the client has not yet used.
func getMessageID() string {
lock.Lock()
messageID++
id := strconv.Itoa(messageID)
lock.Unlock()
return id
}
// mapToStruct serializes a map into a struct.
func mapToStruct(data map[string]interface{}, dest interface{}) error {
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
TagName: "json",
Result: dest,
})
if err != nil {
Logger.Println("initializing decoder:", err)
return err
}
if err = decoder.Decode(data); err != nil {
Logger.Printf("unmarshalling map -> %T: %v", dest, err)
Logger.Printf("input: %#v\n", data)
return err
}
return nil
}

View File

@ -0,0 +1,93 @@
package obsws
import (
"crypto/sha256"
"encoding/base64"
"errors"
"fmt"
"github.com/gorilla/websocket"
)
// Connect opens a WebSocket connection and authenticates if necessary.
func (c *Client) Connect() error {
c.handlers = make(map[string]func(Event))
c.respQ = make(chan map[string]interface{}, bufferSize)
conn, err := connectWS(c.Host, c.Port)
if err != nil {
return err
}
c.conn = conn
// We can't use SendReceive yet because we haven't started polling.
reqGAR := NewGetAuthRequiredRequest()
if err = c.conn.WriteJSON(reqGAR); err != nil {
return err
}
respGAR := &GetAuthRequiredResponse{}
if err = c.conn.ReadJSON(respGAR); err != nil {
return err
}
if !respGAR.AuthRequired {
Logger.Println("logged in (no authentication required)")
c.connected = true
go c.poll()
return nil
}
auth := getAuth(c.Password, respGAR.Salt, respGAR.Challenge)
Logger.Println("auth:", auth)
reqA := NewAuthenticateRequest(auth)
if err = c.conn.WriteJSON(reqA); err != nil {
return err
}
respA := &AuthenticateResponse{}
if err = c.conn.ReadJSON(respA); err != nil {
return err
}
if respA.Status() != "ok" {
return errors.New(respA.Error())
}
Logger.Println("logged in (authentication successful)")
c.connected = true
go c.poll()
return nil
}
// Disconnect closes the WebSocket connection.
func (c *Client) Disconnect() error {
c.connected = false
if err := c.conn.Close(); err != nil {
return err
}
return nil
}
// connectWS opens the WebSocket connection.
func connectWS(host string, port int) (*websocket.Conn, error) {
url := fmt.Sprintf("ws://%s:%d", host, port)
Logger.Println("connecting to", url)
conn, _, err := websocket.DefaultDialer.Dial(url, nil)
if err != nil {
return nil, err
}
return conn, nil
}
// getAuth computes the auth challenge response.
func getAuth(password, salt, challenge string) string {
sha := sha256.Sum256([]byte(password + salt))
b64 := base64.StdEncoding.EncodeToString([]byte(sha[:]))
sha = sha256.Sum256([]byte(b64 + challenge))
b64 = base64.StdEncoding.EncodeToString([]byte(sha[:]))
return b64
}

49
obsws/client_events.go Normal file
View File

@ -0,0 +1,49 @@
package obsws
import (
"errors"
"log"
)
// ErrUnknownEventType is returned when a handler is added for an unknown event.
var ErrUnknownEventType = errors.New("unknown event type")
// AddEventHandler adds a handler function for a given event type.
func (c *Client) AddEventHandler(eventType string, handler func(Event)) error {
if eventMap[eventType] == nil {
return ErrUnknownEventType
}
c.handlers[eventType] = handler
return nil
}
// RemoveEventHandler removes the handler for a given event type.
func (c *Client) RemoveEventHandler(eventType string) {
delete(c.handlers, eventType)
}
// handleEvent runs an event's handler if it exists.
func (c *Client) handleEvent(m map[string]interface{}) {
t := m["update-type"].(string)
log.Println("Handle", t)
eventFn, ok := eventMap[t]
if !ok {
Logger.Println("unknown event type:", m["update-type"])
return
}
event := eventFn()
handler, ok := c.handlers[t]
if !ok {
return
}
if err := mapToStruct(m, event); err != nil {
Logger.Println("event handler failed:", err)
return
}
go handler(derefEvent(event))
}

47
obsws/client_requests.go Normal file
View File

@ -0,0 +1,47 @@
package obsws
import (
"errors"
"time"
)
const interval = time.Millisecond * 50
var (
// ErrNotConnected is returned when a request is sent by a client which is not connected.
ErrNotConnected = errors.New("not connected")
// ErrReceiveTimeout is returned when a response takes too long to arrive.
ErrReceiveTimeout = errors.New("receive timed out")
)
// sendRequest sends a request to the WebSocket server.
func (c *Client) sendRequest(req Request) (chan map[string]interface{}, error) {
if !c.connected {
return nil, ErrNotConnected
}
future := make(chan map[string]interface{})
if err := c.conn.WriteJSON(req); err != nil {
return nil, err
}
Logger.Println("sent request", req.ID())
go func() { future <- c.receive(req.ID()) }()
return future, nil
}
// receive waits until a response matching the given ID arrives.
func (c *Client) receive(id string) map[string]interface{} {
for {
resp := <-c.respQ
if resp["message-id"] == id {
Logger.Println("received response", resp["message-id"])
return resp
}
c.respQ <- resp
time.Sleep(interval)
}
}
// handleResponse sends a response into the queue.
func (c *Client) handleResponse(m map[string]interface{}) {
c.respQ <- m
}

11
obsws/client_test.go Normal file
View File

@ -0,0 +1,11 @@
package obsws
import "testing"
func TestGetAuth(t *testing.T) {
expected := "zTM5ki6L2vVvBQiTG9ckH1Lh64AbnCf6XZ226UmnkIA="
observed := getAuth("password", "salt", "challenge")
if observed != expected {
t.Errorf("expected auth == '%s', got '%s'", expected, observed)
}
}

402
obsws/codegen/protocol.py Normal file
View File

@ -0,0 +1,402 @@
# TODO: No warning is given for struct fields whose names match function names.
# Maybe bring the reserved list back.
import json
import os
import sys
from typing import Dict, List, Tuple
package = "obsws"
doc = "https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md"
disclaimer = """
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
"""
# TODO: Test the less clear ones.
type_map = {
"bool": "bool",
"boolean": "bool",
"int": "int",
"integer": "int",
"float": "float64",
"double": "float64",
"string": "string",
"array": "[]interface{}",
"object": "map[string]interface{}",
"array of objects": "[]map[string]interface{}",
"object|array": "interface{}",
"scene|array": "[]map[string]interface{}",
"source|array": "[]map[string]interface{}",
}
unknown_types = []
def process_json(d: Dict):
"""Generate Go code for the entire protocol file."""
if "--events" in sys.argv or "--all" in sys.argv:
gen_events(d["events"])
if "--requests" in sys.argv or "--all" in sys.argv:
gen_requests(d["requests"])
def gen_category(prefix: str, category: str, data: Dict):
"""Generate all events or requests in one category."""
func = gen_event if prefix == "events" else gen_request
content = "\n".join(
filter(
lambda s: not s.isspace(),
"\n".join(func(thing) for thing in data).split("\n"),
)
)
with open(f"{prefix}_{category}.go".replace(" ", "_"), "w") as f:
f.write(
f"""
package {package}
{disclaimer}
{content}
"""
)
def gen_events(events: Dict):
"""Generate all events."""
for category, data in events.items():
gen_category("events", category, data)
gen_event_utils(events)
def gen_event(data: Dict) -> str:
"""Write Go code with a type definition and interface functions."""
struct = f"""
type {data["name"]}Event struct {{
{go_struct_variables(go_variables(data.get("returns", [])))}
_event `json:",squash"`
}}
"""
description = newlinify(f"{data['name']}Event : {data['description']}")
if not description.endswith("."):
description += "."
if data.get("since"):
description += (
f"\n//\n// Since obs-websocket version: {data['since'].capitalize()}."
)
return f"""
{description}
//
// {doc}#{data["heading"]["text"].lower()}
{struct}
"""
def gen_requests(requests: Dict):
"""Generate all requests and responses."""
for category, data in requests.items():
gen_category("requests", category, data)
def gen_request(data: Dict) -> str:
"""Write Go code with type definitions and interface functions."""
struct = f"""
type {data["name"]}Request struct {{
{go_struct_variables(go_variables(data.get("params", [])))}
_request `json:",squash"`
response chan {data["name"]}Response
}}
"""
description = newlinify(f"{data['name']}Request : {data['description']}")
if description and not description.endswith("."):
description += "."
if data.get("since"):
description += (
f"\n//\n// Since obs-websocket version: {data['since'].capitalize()}."
)
request = f"""
{description}
//
// {doc}#{data["heading"]["text"].lower()}
{struct}
{gen_request_new(data)}
// Send sends the request.
func (r *{data["name"]}Request) Send(c *Client) error {{
if r.sent {{
return ErrAlreadySent
}}
future, err := c.sendRequest(r)
if err != nil {{
return err
}}
r.sent = true
go func() {{
m := <-future
var resp {data["name"]}Response
if err = mapToStruct(m, &resp); err != nil {{
r.err <- err
}} else if resp.Status() != StatusOK {{
r.err <- errors.New(resp.Error())
}} else {{
r.response <- resp
}}
}}()
return nil
}}
// Receive waits for the response.
func (r {data["name"]}Request) Receive() ({data["name"]}Response, error) {{
if !r.sent {{
return {data["name"]}Response{{}}, ErrNotSent
}}
if receiveTimeout == 0 {{
select {{
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return {data["name"]}Response{{}}, err
}}
}} else {{
select {{
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return {data["name"]}Response{{}}, err
case <-time.After(receiveTimeout):
return {data["name"]}Response{{}}, ErrReceiveTimeout
}}
}}
}}
// SendReceive sends the request then immediately waits for the response.
func (r {data["name"]}Request) SendReceive(c *Client) ({data["name"]}Response, error) {{
if err := r.Send(c); err != nil {{
return {data["name"]}Response{{}}, err
}}
return r.Receive()
}}
"""
if data.get("returns"):
struct = f"""
type {data["name"]}Response struct {{
{go_struct_variables(go_variables(data["returns"]))}
_response `json:",squash"`
}}
"""
else:
struct = (
f"""type {data["name"]}Response struct {{ _response `json:",squash"`}}"""
)
description = f"// {data['name']}Response : Response for {data['name']}Request."
if data.get("since"):
description += (
f"\n//\n// Since obs-websocket version: {data['since'].capitalize()}."
)
response = f"""
{description}
//
// {doc}#{data["heading"]["text"].lower()}
{struct}
"""
return f"{request}\n\n{response}"
def gen_request_new(request: Dict):
"""Generate Go code with a New___Request function for a request type."""
base = f"""
// New{request["name"]}Request returns a new {request["name"]}Request.
func New{request["name"]}Request(\
"""
variables = go_variables(request.get("params", []), export=False)
default_args = f"""
_request{{
ID_: getMessageID(),
Type_: "{request["name"]}",
err: make(chan error, 1),
}},
make(chan {request["name"]}Response, 1),
"""
if not variables:
sig = f"{base}) {request['name']}Request"
constructor_args = f"""{{
{default_args}
}}
"""
else:
args = "\n".join(
f"{'_type' if var['name'] == 'type' else var['name']} {var['type']},"
for var in variables
)
constructor_args = (
"{\n"
+ "\n".join(
"_type," if var["name"] == "type" else f"{var['name']},"
for var in variables
)
+ default_args
+ "}"
)
if len(variables) == 1:
sig = f"{base}{args}) {request['name']}Request"
else:
sig = f"""
{base}
{args}
) {request["name"]}Request\
"""
return f"{sig} {{ return {request['name']}Request{constructor_args} }}"
def gen_event_utils(events: Dict):
"""
Generate a Go file with a mappings from type names to structs,
and a function for dereferencing interface pointers.
"""
event_map = {}
event_list = []
for category in events.values():
for e in category:
event_map[e["name"]] = f"func() Event {{ return &{e['name']}Event{{}} }}"
event_list.append(f"*{e['name']}Event")
event_entries = "\n".join(f'"{k}": {v},' for k, v in event_map.items())
event_cases = "\n".join(f"case {e}:\nreturn *e" for e in event_list)
deref = f"""
func derefEvent(e Event) Event {{
switch e := e.(type) {{
{event_cases}
default:
return nil
}}
}}
"""
with open("event_utils.go", "w") as f:
f.write(
f"""
package {package}
{disclaimer}
var eventMap = map[string]func() Event {{
{event_entries}
}}
// derefEvent returns an Event struct from a pointer to an Event struct.
{deref}
"""
)
def go_variables(variables: List[Dict], export: bool = True) -> str:
"""
Convert a list of variable names into Go code to be put
inside a struct definition.
"""
vardicts, varnames = [], []
for v in variables:
typename, optional = optional_type(v["type"])
varname = go_var(v["name"], export=export)
vardicts.append(
{
"name": varname,
"type": type_map[typename.lower()],
"tag": f'`json:"{v["name"]}"`',
"description": v["description"].replace("\n", " "),
"optional": optional,
"unknown": typename.lower() in unknown_types,
"actual_type": v["type"],
"duplicate": varname in varnames,
}
)
varnames.append(varname)
return vardicts
def go_var(s: str, export: bool = True) -> str:
"""Convert a variable name in the input file to a Go variable name."""
s = f"{(str.upper if export else str.lower)(s[0])}{s[1:]}"
for sep in ["-", "_", ".*.", "[].", "."]:
while sep in s:
_len = len(sep)
if s.endswith(sep):
s = s[:-_len]
continue
i = s.find(sep)
s = f"{s[:i]}{s[i+_len].upper()}{s[i+_len+1:]}"
return s.replace("Id", "ID").replace("Obs", "OBS").replace("Fps", "FPS")
def go_struct_variables(variables: List[Dict]) -> str:
"""Generate Go code containing struct field definitions."""
lines = []
for var in variables:
if var["description"]:
description = (
var["description"]
.replace("e.g. ", "e.g.")
.replace(". ", "\n")
.replace("e.g.", "e.g. ")
)
for desc_line in description.split("\n"):
desc_line = desc_line.strip()
if desc_line and not desc_line.endswith("."):
desc_line += "."
lines.append(f"// {desc_line}")
lines.append(f"// Required: {'Yes' if not var['optional'] else 'No'}.")
todos = []
if var["unknown"]:
todos.append(f"Unknown type ({var['actual_type']})")
if var["duplicate"]:
todos.append("Duplicate name")
todos = " ".join(f"TODO: {todo}." for todo in todos)
if todos:
lines.append(f"// {todos}")
lines.append(f"{var['name']} {var['type']} {var['tag']}")
return "\n".join(lines)
def newlinify(s: str, comment: bool = True) -> str:
"""Put each sentence of a string onto its own line."""
s = s.replace("e.g. ", "e.g.").replace(". ", "\n").replace("e.g.", "e.g. ")
if comment:
s = "\n".join(
[f"// {_s}" if not _s.startswith("//") else _s for _s in s.split("\n")]
)
return s
def optional_type(s: str) -> Tuple[str, bool]:
"""Determine if a type is optional and parse the actual type name."""
if s.endswith("(optional)"):
return s[: s.find("(optional)")].strip(), True
return s, False
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Missing filename argument")
exit(1)
if not os.path.isfile(sys.argv[1]):
print(f"file '{sys.argv[1]}' does not exist")
exit(1)
with open(sys.argv[1]) as f:
d = json.load(f)
process_json(d)
os.system("goimports -w *.go")

2
obsws/doc.go Normal file
View File

@ -0,0 +1,2 @@
// Package obsws provides client functionality for obs-websocket.
package obsws

109
obsws/event_utils.go Normal file
View File

@ -0,0 +1,109 @@
package obsws
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
var eventMap = map[string]func() Event{
"SwitchScenes": func() Event { return &SwitchScenesEvent{} },
"ScenesChanged": func() Event { return &ScenesChangedEvent{} },
"SceneCollectionChanged": func() Event { return &SceneCollectionChangedEvent{} },
"SceneCollectionListChanged": func() Event { return &SceneCollectionListChangedEvent{} },
"SwitchTransition": func() Event { return &SwitchTransitionEvent{} },
"TransitionListChanged": func() Event { return &TransitionListChangedEvent{} },
"TransitionDurationChanged": func() Event { return &TransitionDurationChangedEvent{} },
"TransitionBegin": func() Event { return &TransitionBeginEvent{} },
"ProfileChanged": func() Event { return &ProfileChangedEvent{} },
"ProfileListChanged": func() Event { return &ProfileListChangedEvent{} },
"StreamStarting": func() Event { return &StreamStartingEvent{} },
"StreamStarted": func() Event { return &StreamStartedEvent{} },
"StreamStopping": func() Event { return &StreamStoppingEvent{} },
"StreamStopped": func() Event { return &StreamStoppedEvent{} },
"StreamStatus": func() Event { return &StreamStatusEvent{} },
"RecordingStarting": func() Event { return &RecordingStartingEvent{} },
"RecordingStarted": func() Event { return &RecordingStartedEvent{} },
"RecordingStopping": func() Event { return &RecordingStoppingEvent{} },
"RecordingStopped": func() Event { return &RecordingStoppedEvent{} },
"ReplayStarting": func() Event { return &ReplayStartingEvent{} },
"ReplayStarted": func() Event { return &ReplayStartedEvent{} },
"ReplayStopping": func() Event { return &ReplayStoppingEvent{} },
"ReplayStopped": func() Event { return &ReplayStoppedEvent{} },
"Exiting": func() Event { return &ExitingEvent{} },
"Heartbeat": func() Event { return &HeartbeatEvent{} },
"SourceOrderChanged": func() Event { return &SourceOrderChangedEvent{} },
"SceneItemAdded": func() Event { return &SceneItemAddedEvent{} },
"SceneItemRemoved": func() Event { return &SceneItemRemovedEvent{} },
"SceneItemVisibilityChanged": func() Event { return &SceneItemVisibilityChangedEvent{} },
"PreviewSceneChanged": func() Event { return &PreviewSceneChangedEvent{} },
"StudioModeSwitched": func() Event { return &StudioModeSwitchedEvent{} },
}
// derefEvent returns an Event struct from a pointer to an Event struct.
func derefEvent(e Event) Event {
switch e := e.(type) {
case *SwitchScenesEvent:
return *e
case *ScenesChangedEvent:
return *e
case *SceneCollectionChangedEvent:
return *e
case *SceneCollectionListChangedEvent:
return *e
case *SwitchTransitionEvent:
return *e
case *TransitionListChangedEvent:
return *e
case *TransitionDurationChangedEvent:
return *e
case *TransitionBeginEvent:
return *e
case *ProfileChangedEvent:
return *e
case *ProfileListChangedEvent:
return *e
case *StreamStartingEvent:
return *e
case *StreamStartedEvent:
return *e
case *StreamStoppingEvent:
return *e
case *StreamStoppedEvent:
return *e
case *StreamStatusEvent:
return *e
case *RecordingStartingEvent:
return *e
case *RecordingStartedEvent:
return *e
case *RecordingStoppingEvent:
return *e
case *RecordingStoppedEvent:
return *e
case *ReplayStartingEvent:
return *e
case *ReplayStartedEvent:
return *e
case *ReplayStoppingEvent:
return *e
case *ReplayStoppedEvent:
return *e
case *ExitingEvent:
return *e
case *HeartbeatEvent:
return *e
case *SourceOrderChangedEvent:
return *e
case *SceneItemAddedEvent:
return *e
case *SceneItemRemovedEvent:
return *e
case *SceneItemVisibilityChangedEvent:
return *e
case *PreviewSceneChangedEvent:
return *e
case *StudioModeSwitchedEvent:
return *e
default:
return nil
}
}

24
obsws/events.go Normal file
View File

@ -0,0 +1,24 @@
package obsws
// Event is broadcast by the server to each connected client when a recognized action occurs within OBS.
type Event interface {
Type() string
StreamTimecode() string
RecTimecode() string
}
// https://github.com/Palakis/obs-websocket/blob/master/docs/generated/protocol.md#events
type _event struct {
Type_ string `json:"update-type"`
StreamTimecode_ string `json:"stream-timecode"`
RecTimecode_ string `json:"rec-timecode"`
}
// Type returns the event's update type.
func (e _event) Type() string { return e.Type_ }
// StreamTimeode returns the event's stream timecode.
func (e _event) StreamTimecode() string { return e.StreamTimecode_ }
// RecTimecode returns the event's recording timecode.
func (e _event) RecTimecode() string { return e.RecTimecode_ }

44
obsws/events_general.go Normal file
View File

@ -0,0 +1,44 @@
package obsws
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// HeartbeatEvent : Emitted every 2 seconds after enabling it by calling SetHeartbeat.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#heartbeat
type HeartbeatEvent struct {
// Toggles between every JSON message as an "I am alive" indicator.
// Required: Yes.
Pulse bool `json:"pulse"`
// Current active profile.
// Required: No.
CurrentProfile string `json:"current-profile"`
// Current active scene.
// Required: No.
CurrentScene string `json:"current-scene"`
// Current streaming state.
// Required: No.
Streaming bool `json:"streaming"`
// Total time (in seconds) since the stream started.
// Required: No.
TotalStreamTime int `json:"total-stream-time"`
// Total bytes sent since the stream started.
// Required: No.
TotalStreamBytes int `json:"total-stream-bytes"`
// Total frames streamed since the stream started.
// Required: No.
TotalStreamFrames int `json:"total-stream-frames"`
// Current recording state.
// Required: No.
Recording bool `json:"recording"`
// Total time (in seconds) since recording started.
// Required: No.
TotalRecordTime int `json:"total-record-time"`
// Total bytes recorded since the recording started.
// Required: No.
TotalRecordBytes int `json:"total-record-bytes"`
// Total frames recorded since the recording started.
// Required: No.
TotalRecordFrames int `json:"total-record-frames"`
_event `json:",squash"`
}

13
obsws/events_other.go Normal file
View File

@ -0,0 +1,13 @@
package obsws
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// ExitingEvent : OBS is exiting.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#exiting
type ExitingEvent struct {
_event `json:",squash"`
}

22
obsws/events_profiles.go Normal file
View File

@ -0,0 +1,22 @@
package obsws
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// ProfileChangedEvent : Triggered when switching to another profile or when renaming the current profile.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#profilechanged
type ProfileChangedEvent struct {
_event `json:",squash"`
}
// ProfileListChangedEvent : Triggered when a profile is created, added, renamed, or removed.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#profilelistchanged
type ProfileListChangedEvent struct {
_event `json:",squash"`
}

40
obsws/events_recording.go Normal file
View File

@ -0,0 +1,40 @@
package obsws
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// RecordingStartingEvent : A request to start recording has been issued.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#recordingstarting
type RecordingStartingEvent struct {
_event `json:",squash"`
}
// RecordingStartedEvent : Recording started successfully.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#recordingstarted
type RecordingStartedEvent struct {
_event `json:",squash"`
}
// RecordingStoppingEvent : A request to stop recording has been issued.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#recordingstopping
type RecordingStoppingEvent struct {
_event `json:",squash"`
}
// RecordingStoppedEvent : Recording stopped successfully.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#recordingstopped
type RecordingStoppedEvent struct {
_event `json:",squash"`
}

View File

@ -0,0 +1,40 @@
package obsws
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// ReplayStartingEvent : A request to start the replay buffer has been issued.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#replaystarting
type ReplayStartingEvent struct {
_event `json:",squash"`
}
// ReplayStartedEvent : Replay Buffer started successfully.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#replaystarted
type ReplayStartedEvent struct {
_event `json:",squash"`
}
// ReplayStoppingEvent : A request to stop the replay buffer has been issued.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#replaystopping
type ReplayStoppingEvent struct {
_event `json:",squash"`
}
// ReplayStoppedEvent : Replay Buffer stopped successfully.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#replaystopped
type ReplayStoppedEvent struct {
_event `json:",squash"`
}

47
obsws/events_scenes.go Normal file
View File

@ -0,0 +1,47 @@
package obsws
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// SwitchScenesEvent : Indicates a scene change.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#switchscenes
type SwitchScenesEvent struct {
// The new scene.
// Required: Yes.
SceneName string `json:"scene-name"`
// List of sources in the new scene.
// Required: Yes.
Sources []interface{} `json:"sources"`
_event `json:",squash"`
}
// ScenesChangedEvent : The scene list has been modified.
// Scenes have been added, removed, or renamed.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#sceneschanged
type ScenesChangedEvent struct {
_event `json:",squash"`
}
// SceneCollectionChangedEvent : Triggered when switching to another scene collection or when renaming the current scene collection.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#scenecollectionchanged
type SceneCollectionChangedEvent struct {
_event `json:",squash"`
}
// SceneCollectionListChangedEvent : Triggered when a scene collection is created, added, renamed, or removed.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#scenecollectionlistchanged
type SceneCollectionListChangedEvent struct {
_event `json:",squash"`
}

64
obsws/events_sources.go Normal file
View File

@ -0,0 +1,64 @@
package obsws
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// SourceOrderChangedEvent : Scene items have been reordered.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#sourceorderchanged
type SourceOrderChangedEvent struct {
// Name of the scene where items have been reordered.
// Required: Yes.
SceneName string `json:"scene-name"`
_event `json:",squash"`
}
// SceneItemAddedEvent : An item has been added to the current scene.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#sceneitemadded
type SceneItemAddedEvent struct {
// Name of the scene.
// Required: Yes.
SceneName string `json:"scene-name"`
// Name of the item added to the scene.
// Required: Yes.
ItemName string `json:"item-name"`
_event `json:",squash"`
}
// SceneItemRemovedEvent : An item has been removed from the current scene.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#sceneitemremoved
type SceneItemRemovedEvent struct {
// Name of the scene.
// Required: Yes.
SceneName string `json:"scene-name"`
// Name of the item removed from the scene.
// Required: Yes.
ItemName string `json:"item-name"`
_event `json:",squash"`
}
// SceneItemVisibilityChangedEvent : An item's visibility has been toggled.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#sceneitemvisibilitychanged
type SceneItemVisibilityChangedEvent struct {
// Name of the scene.
// Required: Yes.
SceneName string `json:"scene-name"`
// Name of the item in the scene.
// Required: Yes.
ItemName string `json:"item-name"`
// New visibility state of the item.
// Required: Yes.
ItemVisible bool `json:"item-visible"`
_event `json:",squash"`
}

88
obsws/events_streaming.go Normal file
View File

@ -0,0 +1,88 @@
package obsws
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// StreamStartingEvent : A request to start streaming has been issued.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#streamstarting
type StreamStartingEvent struct {
// Always false (retrocompatibility).
// Required: Yes.
PreviewOnly bool `json:"preview-only"`
_event `json:",squash"`
}
// StreamStartedEvent : Streaming started successfully.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#streamstarted
type StreamStartedEvent struct {
_event `json:",squash"`
}
// StreamStoppingEvent : A request to stop streaming has been issued.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#streamstopping
type StreamStoppingEvent struct {
// Always false (retrocompatibility).
// Required: Yes.
PreviewOnly bool `json:"preview-only"`
_event `json:",squash"`
}
// StreamStoppedEvent : Streaming stopped successfully.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#streamstopped
type StreamStoppedEvent struct {
_event `json:",squash"`
}
// StreamStatusEvent : Emit every 2 seconds.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#streamstatus
type StreamStatusEvent struct {
// Current streaming state.
// Required: Yes.
Streaming bool `json:"streaming"`
// Current recording state.
// Required: Yes.
Recording bool `json:"recording"`
// Current replay state.
// Required: Yes.
Replay bool `json:"replay-buffer-active"`
// Always false (retrocompatibility).
// Required: Yes.
PreviewOnly bool `json:"preview-only"`
// Amount of data per second (in bytes) transmitted by the stream encoder.
// Required: Yes.
BytesPerSec int `json:"bytes-per-sec"`
// Amount of data per second (in kilobits) transmitted by the stream encoder.
// Required: Yes.
KbitsPerSec int `json:"kbits-per-sec"`
// Percentage of dropped frames.
// Required: Yes.
Strain float64 `json:"strain"`
// Total time (in seconds) since the stream started.
// Required: Yes.
TotalStreamTime int `json:"total-stream-time"`
// Total number of frames transmitted since the stream started.
// Required: Yes.
NumTotalFrames int `json:"num-total-frames"`
// Number of frames dropped by the encoder since the stream started.
// Required: Yes.
NumDroppedFrames int `json:"num-dropped-frames"`
// Current framerate.
// Required: Yes.
FPS float64 `json:"fps"`
_event `json:",squash"`
}

View File

@ -0,0 +1,32 @@
package obsws
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// PreviewSceneChangedEvent : The selected preview scene has changed (only available in Studio Mode).
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#previewscenechanged
type PreviewSceneChangedEvent struct {
// Name of the scene being previewed.
// Required: Yes.
SceneName string `json:"scene-name"`
// List of sources composing the scene.
// Same specification as [`GetCurrentScene`](#getcurrentscene).
// Required: Yes.
Sources []map[string]interface{} `json:"sources"`
_event `json:",squash"`
}
// StudioModeSwitchedEvent : Studio Mode has been enabled or disabled.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#studiomodeswitched
type StudioModeSwitchedEvent struct {
// The new enabled state of Studio Mode.
// Required: Yes.
NewState bool `json:"new-state"`
_event `json:",squash"`
}

View File

@ -0,0 +1,59 @@
package obsws
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// SwitchTransitionEvent : The active transition has been changed.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#switchtransition
type SwitchTransitionEvent struct {
// The name of the new active transition.
// Required: Yes.
TransitionName string `json:"transition-name"`
_event `json:",squash"`
}
// TransitionListChangedEvent : The list of available transitions has been modified.
// Transitions have been added, removed, or renamed.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#transitionlistchanged
type TransitionListChangedEvent struct {
_event `json:",squash"`
}
// TransitionDurationChangedEvent : The active transition duration has been changed.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#transitiondurationchanged
type TransitionDurationChangedEvent struct {
// New transition duration.
// Required: Yes.
NewDuration int `json:"new-duration"`
_event `json:",squash"`
}
// TransitionBeginEvent : A transition (other than "cut") has begun.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#transitionbegin
type TransitionBeginEvent struct {
// Transition name.
// Required: Yes.
Name string `json:"name"`
// Transition duration (in milliseconds).
// Required: Yes.
Duration int `json:"duration"`
// Source scene of the transition.
// Required: Yes.
FromScene string `json:"from-scene"`
// Destination scene of the transition.
// Required: Yes.
ToScene string `json:"to-scene"`
_event `json:",squash"`
}

4
obsws/go.sum Normal file
View File

@ -0,0 +1,4 @@
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=

8
obsws/logger.go Normal file
View File

@ -0,0 +1,8 @@
package obsws
import (
"log"
"os"
)
var Logger = log.New(os.Stdout, "[obsws] ", log.LstdFlags)

65
obsws/requests.go Normal file
View File

@ -0,0 +1,65 @@
package obsws
import "errors"
const (
// StatusOK indicates that the request was successful.
StatusOK = "ok"
// StatusError indicates that the request was unsuccessful.
StatusError = "error"
)
var (
// ErrNotSent is returned when you call Receive on a request that has not been sent.
ErrNotSent = errors.New("request not yet sent")
// ErrAlreadySent is returned when a request has already been sent.
ErrAlreadySent = errors.New("request already sent")
)
// Request is a request to obs-websocket.
type Request interface {
ID() string
Type() string
Send(*Client) error
}
// Response is a response from obs-websocket.
type Response interface {
ID() string
Status() string
Error() string
}
// https://github.com/Palakis/obs-websocket/blob/master/docs/generated/protocol.md#requests
type _request struct {
ID_ string `json:"message-id"`
Type_ string `json:"request-type"`
sent bool
err chan error
}
func (r _request) Send(c *Client) error { return nil }
// ID returns the request's message ID.
func (r _request) ID() string { return r.ID_ }
// Type returns the request's message type.
func (r _request) Type() string { return r.Type_ }
// https://github.com/Palakis/obs-websocket/blob/master/docs/generated/protocol.md#requests
type _response struct {
ID_ string `json:"message-id"`
Status_ string `json:"status"`
Error_ string `json:"error"`
}
// ID returns the response's message ID.
func (r _response) ID() string { return r.ID_ }
// Status returns the response's status.
func (r _response) Status() string { return r.Status_ }
// Error returns the response's error.
// When using Receive or SendReceive, this should always return an empty string,
// because the error will have been returned explictly instead of stored here.
func (r _response) Error() string { return r.Error_ }

568
obsws/requests_general.go Normal file
View File

@ -0,0 +1,568 @@
package obsws
import (
"errors"
"time"
)
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// GetVersionRequest : Returns the latest version of the plugin and the API.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getversion
type GetVersionRequest struct {
_request `json:",squash"`
response chan GetVersionResponse
}
// NewGetVersionRequest returns a new GetVersionRequest.
func NewGetVersionRequest() GetVersionRequest {
return GetVersionRequest{
_request{
ID_: getMessageID(),
Type_: "GetVersion",
err: make(chan error, 1),
},
make(chan GetVersionResponse, 1),
}
}
// Send sends the request.
func (r *GetVersionRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetVersionResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetVersionRequest) Receive() (GetVersionResponse, error) {
if !r.sent {
return GetVersionResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetVersionResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetVersionResponse{}, err
case <-time.After(receiveTimeout):
return GetVersionResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetVersionRequest) SendReceive(c *Client) (GetVersionResponse, error) {
if err := r.Send(c); err != nil {
return GetVersionResponse{}, err
}
return r.Receive()
}
// GetVersionResponse : Response for GetVersionRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getversion
type GetVersionResponse struct {
// OBSRemote compatible API version.
// Fixed to 1.1 for retrocompatibility.
// Required: Yes.
Version float64 `json:"version"`
// obs-websocket plugin version.
// Required: Yes.
OBSWebsocketVersion string `json:"obs-websocket-version"`
// OBS Studio program version.
// Required: Yes.
OBSStudioVersion string `json:"obs-studio-version"`
// List of available request types, formatted as a comma-separated list string (e.g. : "Method1,Method2,Method3").
// Required: Yes.
AvailableRequests string `json:"available-requests"`
_response `json:",squash"`
}
// GetAuthRequiredRequest : Tells the client if authentication is required
// If so, returns authentication parameters `challenge`
// and `salt` (see "Authentication" for more information).
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getauthrequired
type GetAuthRequiredRequest struct {
_request `json:",squash"`
response chan GetAuthRequiredResponse
}
// NewGetAuthRequiredRequest returns a new GetAuthRequiredRequest.
func NewGetAuthRequiredRequest() GetAuthRequiredRequest {
return GetAuthRequiredRequest{
_request{
ID_: getMessageID(),
Type_: "GetAuthRequired",
err: make(chan error, 1),
},
make(chan GetAuthRequiredResponse, 1),
}
}
// Send sends the request.
func (r *GetAuthRequiredRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetAuthRequiredResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetAuthRequiredRequest) Receive() (GetAuthRequiredResponse, error) {
if !r.sent {
return GetAuthRequiredResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetAuthRequiredResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetAuthRequiredResponse{}, err
case <-time.After(receiveTimeout):
return GetAuthRequiredResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetAuthRequiredRequest) SendReceive(c *Client) (GetAuthRequiredResponse, error) {
if err := r.Send(c); err != nil {
return GetAuthRequiredResponse{}, err
}
return r.Receive()
}
// GetAuthRequiredResponse : Response for GetAuthRequiredRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getauthrequired
type GetAuthRequiredResponse struct {
// Indicates whether authentication is required.
// Required: Yes.
AuthRequired bool `json:"authRequired"`
// Required: No.
Challenge string `json:"challenge"`
// Required: No.
Salt string `json:"salt"`
_response `json:",squash"`
}
// AuthenticateRequest : Attempt to authenticate the client to the server.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#authenticate
type AuthenticateRequest struct {
// Response to the auth challenge (see "Authentication" for more information).
// Required: Yes.
Auth string `json:"auth"`
_request `json:",squash"`
response chan AuthenticateResponse
}
// NewAuthenticateRequest returns a new AuthenticateRequest.
func NewAuthenticateRequest(auth string) AuthenticateRequest {
return AuthenticateRequest{
auth,
_request{
ID_: getMessageID(),
Type_: "Authenticate",
err: make(chan error, 1),
},
make(chan AuthenticateResponse, 1),
}
}
// Send sends the request.
func (r *AuthenticateRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp AuthenticateResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r AuthenticateRequest) Receive() (AuthenticateResponse, error) {
if !r.sent {
return AuthenticateResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return AuthenticateResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return AuthenticateResponse{}, err
case <-time.After(receiveTimeout):
return AuthenticateResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r AuthenticateRequest) SendReceive(c *Client) (AuthenticateResponse, error) {
if err := r.Send(c); err != nil {
return AuthenticateResponse{}, err
}
return r.Receive()
}
// AuthenticateResponse : Response for AuthenticateRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#authenticate
type AuthenticateResponse struct {
_response `json:",squash"`
}
// SetHeartbeatRequest : Enable/disable sending of the Heartbeat event.
//
// Since obs-websocket version: 4.3.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setheartbeat
type SetHeartbeatRequest struct {
// Starts/Stops emitting heartbeat messages.
// Required: Yes.
Enable bool `json:"enable"`
_request `json:",squash"`
response chan SetHeartbeatResponse
}
// NewSetHeartbeatRequest returns a new SetHeartbeatRequest.
func NewSetHeartbeatRequest(enable bool) SetHeartbeatRequest {
return SetHeartbeatRequest{
enable,
_request{
ID_: getMessageID(),
Type_: "SetHeartbeat",
err: make(chan error, 1),
},
make(chan SetHeartbeatResponse, 1),
}
}
// Send sends the request.
func (r *SetHeartbeatRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetHeartbeatResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetHeartbeatRequest) Receive() (SetHeartbeatResponse, error) {
if !r.sent {
return SetHeartbeatResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetHeartbeatResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetHeartbeatResponse{}, err
case <-time.After(receiveTimeout):
return SetHeartbeatResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetHeartbeatRequest) SendReceive(c *Client) (SetHeartbeatResponse, error) {
if err := r.Send(c); err != nil {
return SetHeartbeatResponse{}, err
}
return r.Receive()
}
// SetHeartbeatResponse : Response for SetHeartbeatRequest.
//
// Since obs-websocket version: 4.3.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setheartbeat
type SetHeartbeatResponse struct {
_response `json:",squash"`
}
// SetFilenameFormattingRequest : Set the filename formatting string.
//
// Since obs-websocket version: 4.3.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setfilenameformatting
type SetFilenameFormattingRequest struct {
// Filename formatting string to set.
// Required: Yes.
FilenameFormatting string `json:"filename-formatting"`
_request `json:",squash"`
response chan SetFilenameFormattingResponse
}
// NewSetFilenameFormattingRequest returns a new SetFilenameFormattingRequest.
func NewSetFilenameFormattingRequest(filenameFormatting string) SetFilenameFormattingRequest {
return SetFilenameFormattingRequest{
filenameFormatting,
_request{
ID_: getMessageID(),
Type_: "SetFilenameFormatting",
err: make(chan error, 1),
},
make(chan SetFilenameFormattingResponse, 1),
}
}
// Send sends the request.
func (r *SetFilenameFormattingRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetFilenameFormattingResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetFilenameFormattingRequest) Receive() (SetFilenameFormattingResponse, error) {
if !r.sent {
return SetFilenameFormattingResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetFilenameFormattingResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetFilenameFormattingResponse{}, err
case <-time.After(receiveTimeout):
return SetFilenameFormattingResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetFilenameFormattingRequest) SendReceive(c *Client) (SetFilenameFormattingResponse, error) {
if err := r.Send(c); err != nil {
return SetFilenameFormattingResponse{}, err
}
return r.Receive()
}
// SetFilenameFormattingResponse : Response for SetFilenameFormattingRequest.
//
// Since obs-websocket version: 4.3.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setfilenameformatting
type SetFilenameFormattingResponse struct {
_response `json:",squash"`
}
// GetFilenameFormattingRequest : Get the filename formatting string.
//
// Since obs-websocket version: 4.3.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getfilenameformatting
type GetFilenameFormattingRequest struct {
_request `json:",squash"`
response chan GetFilenameFormattingResponse
}
// NewGetFilenameFormattingRequest returns a new GetFilenameFormattingRequest.
func NewGetFilenameFormattingRequest() GetFilenameFormattingRequest {
return GetFilenameFormattingRequest{
_request{
ID_: getMessageID(),
Type_: "GetFilenameFormatting",
err: make(chan error, 1),
},
make(chan GetFilenameFormattingResponse, 1),
}
}
// Send sends the request.
func (r *GetFilenameFormattingRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetFilenameFormattingResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetFilenameFormattingRequest) Receive() (GetFilenameFormattingResponse, error) {
if !r.sent {
return GetFilenameFormattingResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetFilenameFormattingResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetFilenameFormattingResponse{}, err
case <-time.After(receiveTimeout):
return GetFilenameFormattingResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetFilenameFormattingRequest) SendReceive(c *Client) (GetFilenameFormattingResponse, error) {
if err := r.Send(c); err != nil {
return GetFilenameFormattingResponse{}, err
}
return r.Receive()
}
// GetFilenameFormattingResponse : Response for GetFilenameFormattingRequest.
//
// Since obs-websocket version: 4.3.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getfilenameformatting
type GetFilenameFormattingResponse struct {
// Current filename formatting string.
// Required: Yes.
FilenameFormatting string `json:"filename-formatting"`
_response `json:",squash"`
}

280
obsws/requests_profiles.go Normal file
View File

@ -0,0 +1,280 @@
package obsws
import (
"errors"
"time"
)
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// SetCurrentProfileRequest : Set the currently active profile.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setcurrentprofile
type SetCurrentProfileRequest struct {
// Name of the desired profile.
// Required: Yes.
ProfileName string `json:"profile-name"`
_request `json:",squash"`
response chan SetCurrentProfileResponse
}
// NewSetCurrentProfileRequest returns a new SetCurrentProfileRequest.
func NewSetCurrentProfileRequest(profileName string) SetCurrentProfileRequest {
return SetCurrentProfileRequest{
profileName,
_request{
ID_: getMessageID(),
Type_: "SetCurrentProfile",
err: make(chan error, 1),
},
make(chan SetCurrentProfileResponse, 1),
}
}
// Send sends the request.
func (r *SetCurrentProfileRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetCurrentProfileResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetCurrentProfileRequest) Receive() (SetCurrentProfileResponse, error) {
if !r.sent {
return SetCurrentProfileResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetCurrentProfileResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetCurrentProfileResponse{}, err
case <-time.After(receiveTimeout):
return SetCurrentProfileResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetCurrentProfileRequest) SendReceive(c *Client) (SetCurrentProfileResponse, error) {
if err := r.Send(c); err != nil {
return SetCurrentProfileResponse{}, err
}
return r.Receive()
}
// SetCurrentProfileResponse : Response for SetCurrentProfileRequest.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setcurrentprofile
type SetCurrentProfileResponse struct {
_response `json:",squash"`
}
// GetCurrentProfileRequest : Get the name of the current profile.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getcurrentprofile
type GetCurrentProfileRequest struct {
_request `json:",squash"`
response chan GetCurrentProfileResponse
}
// NewGetCurrentProfileRequest returns a new GetCurrentProfileRequest.
func NewGetCurrentProfileRequest() GetCurrentProfileRequest {
return GetCurrentProfileRequest{
_request{
ID_: getMessageID(),
Type_: "GetCurrentProfile",
err: make(chan error, 1),
},
make(chan GetCurrentProfileResponse, 1),
}
}
// Send sends the request.
func (r *GetCurrentProfileRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetCurrentProfileResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetCurrentProfileRequest) Receive() (GetCurrentProfileResponse, error) {
if !r.sent {
return GetCurrentProfileResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetCurrentProfileResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetCurrentProfileResponse{}, err
case <-time.After(receiveTimeout):
return GetCurrentProfileResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetCurrentProfileRequest) SendReceive(c *Client) (GetCurrentProfileResponse, error) {
if err := r.Send(c); err != nil {
return GetCurrentProfileResponse{}, err
}
return r.Receive()
}
// GetCurrentProfileResponse : Response for GetCurrentProfileRequest.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getcurrentprofile
type GetCurrentProfileResponse struct {
// Name of the currently active profile.
// Required: Yes.
ProfileName string `json:"profile-name"`
_response `json:",squash"`
}
// ListProfilesRequest : Get a list of available profiles.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#listprofiles
type ListProfilesRequest struct {
_request `json:",squash"`
response chan ListProfilesResponse
}
// NewListProfilesRequest returns a new ListProfilesRequest.
func NewListProfilesRequest() ListProfilesRequest {
return ListProfilesRequest{
_request{
ID_: getMessageID(),
Type_: "ListProfiles",
err: make(chan error, 1),
},
make(chan ListProfilesResponse, 1),
}
}
// Send sends the request.
func (r *ListProfilesRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp ListProfilesResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r ListProfilesRequest) Receive() (ListProfilesResponse, error) {
if !r.sent {
return ListProfilesResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return ListProfilesResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return ListProfilesResponse{}, err
case <-time.After(receiveTimeout):
return ListProfilesResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r ListProfilesRequest) SendReceive(c *Client) (ListProfilesResponse, error) {
if err := r.Send(c); err != nil {
return ListProfilesResponse{}, err
}
return r.Receive()
}
// ListProfilesResponse : Response for ListProfilesRequest.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#listprofiles
type ListProfilesResponse struct {
// List of available profiles.
// Required: Yes.
Profiles interface{} `json:"profiles"`
_response `json:",squash"`
}

453
obsws/requests_recording.go Normal file
View File

@ -0,0 +1,453 @@
package obsws
import (
"errors"
"time"
)
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// StartStopRecordingRequest : Toggle recording on or off.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startstoprecording
type StartStopRecordingRequest struct {
_request `json:",squash"`
response chan StartStopRecordingResponse
}
// NewStartStopRecordingRequest returns a new StartStopRecordingRequest.
func NewStartStopRecordingRequest() StartStopRecordingRequest {
return StartStopRecordingRequest{
_request{
ID_: getMessageID(),
Type_: "StartStopRecording",
err: make(chan error, 1),
},
make(chan StartStopRecordingResponse, 1),
}
}
// Send sends the request.
func (r *StartStopRecordingRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp StartStopRecordingResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r StartStopRecordingRequest) Receive() (StartStopRecordingResponse, error) {
if !r.sent {
return StartStopRecordingResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartStopRecordingResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartStopRecordingResponse{}, err
case <-time.After(receiveTimeout):
return StartStopRecordingResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r StartStopRecordingRequest) SendReceive(c *Client) (StartStopRecordingResponse, error) {
if err := r.Send(c); err != nil {
return StartStopRecordingResponse{}, err
}
return r.Receive()
}
// StartStopRecordingResponse : Response for StartStopRecordingRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startstoprecording
type StartStopRecordingResponse struct {
_response `json:",squash"`
}
// StartRecordingRequest : Start recording.
// Will return an `error` if recording is already active.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startrecording
type StartRecordingRequest struct {
_request `json:",squash"`
response chan StartRecordingResponse
}
// NewStartRecordingRequest returns a new StartRecordingRequest.
func NewStartRecordingRequest() StartRecordingRequest {
return StartRecordingRequest{
_request{
ID_: getMessageID(),
Type_: "StartRecording",
err: make(chan error, 1),
},
make(chan StartRecordingResponse, 1),
}
}
// Send sends the request.
func (r *StartRecordingRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp StartRecordingResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r StartRecordingRequest) Receive() (StartRecordingResponse, error) {
if !r.sent {
return StartRecordingResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartRecordingResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartRecordingResponse{}, err
case <-time.After(receiveTimeout):
return StartRecordingResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r StartRecordingRequest) SendReceive(c *Client) (StartRecordingResponse, error) {
if err := r.Send(c); err != nil {
return StartRecordingResponse{}, err
}
return r.Receive()
}
// StartRecordingResponse : Response for StartRecordingRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startrecording
type StartRecordingResponse struct {
_response `json:",squash"`
}
// StopRecordingRequest : Stop recording.
// Will return an `error` if recording is not active.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#stoprecording
type StopRecordingRequest struct {
_request `json:",squash"`
response chan StopRecordingResponse
}
// NewStopRecordingRequest returns a new StopRecordingRequest.
func NewStopRecordingRequest() StopRecordingRequest {
return StopRecordingRequest{
_request{
ID_: getMessageID(),
Type_: "StopRecording",
err: make(chan error, 1),
},
make(chan StopRecordingResponse, 1),
}
}
// Send sends the request.
func (r *StopRecordingRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp StopRecordingResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r StopRecordingRequest) Receive() (StopRecordingResponse, error) {
if !r.sent {
return StopRecordingResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StopRecordingResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StopRecordingResponse{}, err
case <-time.After(receiveTimeout):
return StopRecordingResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r StopRecordingRequest) SendReceive(c *Client) (StopRecordingResponse, error) {
if err := r.Send(c); err != nil {
return StopRecordingResponse{}, err
}
return r.Receive()
}
// StopRecordingResponse : Response for StopRecordingRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#stoprecording
type StopRecordingResponse struct {
_response `json:",squash"`
}
// SetRecordingFolderRequest : Change the current recording folder.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setrecordingfolder
type SetRecordingFolderRequest struct {
// Path of the recording folder.
// Required: Yes.
RecFolder string `json:"rec-folder"`
_request `json:",squash"`
response chan SetRecordingFolderResponse
}
// NewSetRecordingFolderRequest returns a new SetRecordingFolderRequest.
func NewSetRecordingFolderRequest(recFolder string) SetRecordingFolderRequest {
return SetRecordingFolderRequest{
recFolder,
_request{
ID_: getMessageID(),
Type_: "SetRecordingFolder",
err: make(chan error, 1),
},
make(chan SetRecordingFolderResponse, 1),
}
}
// Send sends the request.
func (r *SetRecordingFolderRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetRecordingFolderResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetRecordingFolderRequest) Receive() (SetRecordingFolderResponse, error) {
if !r.sent {
return SetRecordingFolderResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetRecordingFolderResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetRecordingFolderResponse{}, err
case <-time.After(receiveTimeout):
return SetRecordingFolderResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetRecordingFolderRequest) SendReceive(c *Client) (SetRecordingFolderResponse, error) {
if err := r.Send(c); err != nil {
return SetRecordingFolderResponse{}, err
}
return r.Receive()
}
// SetRecordingFolderResponse : Response for SetRecordingFolderRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setrecordingfolder
type SetRecordingFolderResponse struct {
_response `json:",squash"`
}
// GetRecordingFolderRequest : Get the path of the current recording folder.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getrecordingfolder
type GetRecordingFolderRequest struct {
_request `json:",squash"`
response chan GetRecordingFolderResponse
}
// NewGetRecordingFolderRequest returns a new GetRecordingFolderRequest.
func NewGetRecordingFolderRequest() GetRecordingFolderRequest {
return GetRecordingFolderRequest{
_request{
ID_: getMessageID(),
Type_: "GetRecordingFolder",
err: make(chan error, 1),
},
make(chan GetRecordingFolderResponse, 1),
}
}
// Send sends the request.
func (r *GetRecordingFolderRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetRecordingFolderResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetRecordingFolderRequest) Receive() (GetRecordingFolderResponse, error) {
if !r.sent {
return GetRecordingFolderResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetRecordingFolderResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetRecordingFolderResponse{}, err
case <-time.After(receiveTimeout):
return GetRecordingFolderResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetRecordingFolderRequest) SendReceive(c *Client) (GetRecordingFolderResponse, error) {
if err := r.Send(c); err != nil {
return GetRecordingFolderResponse{}, err
}
return r.Receive()
}
// GetRecordingFolderResponse : Response for GetRecordingFolderRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getrecordingfolder
type GetRecordingFolderResponse struct {
// Path of the recording folder.
// Required: Yes.
RecFolder string `json:"rec-folder"`
_response `json:",squash"`
}

View File

@ -0,0 +1,365 @@
package obsws
import (
"errors"
"time"
)
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// StartStopReplayBufferRequest : Toggle the Replay Buffer on/off.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startstopreplaybuffer
type StartStopReplayBufferRequest struct {
_request `json:",squash"`
response chan StartStopReplayBufferResponse
}
// NewStartStopReplayBufferRequest returns a new StartStopReplayBufferRequest.
func NewStartStopReplayBufferRequest() StartStopReplayBufferRequest {
return StartStopReplayBufferRequest{
_request{
ID_: getMessageID(),
Type_: "StartStopReplayBuffer",
err: make(chan error, 1),
},
make(chan StartStopReplayBufferResponse, 1),
}
}
// Send sends the request.
func (r *StartStopReplayBufferRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp StartStopReplayBufferResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r StartStopReplayBufferRequest) Receive() (StartStopReplayBufferResponse, error) {
if !r.sent {
return StartStopReplayBufferResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartStopReplayBufferResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartStopReplayBufferResponse{}, err
case <-time.After(receiveTimeout):
return StartStopReplayBufferResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r StartStopReplayBufferRequest) SendReceive(c *Client) (StartStopReplayBufferResponse, error) {
if err := r.Send(c); err != nil {
return StartStopReplayBufferResponse{}, err
}
return r.Receive()
}
// StartStopReplayBufferResponse : Response for StartStopReplayBufferRequest.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startstopreplaybuffer
type StartStopReplayBufferResponse struct {
_response `json:",squash"`
}
// StartReplayBufferRequest : Start recording into the Replay Buffer.
// Will return an `error` if the Replay Buffer is already active or if the
// "Save Replay Buffer" hotkey is not set in OBS' settings.
// Setting this hotkey is mandatory, even when triggering saves only
// through obs-websocket.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startreplaybuffer
type StartReplayBufferRequest struct {
_request `json:",squash"`
response chan StartReplayBufferResponse
}
// NewStartReplayBufferRequest returns a new StartReplayBufferRequest.
func NewStartReplayBufferRequest() StartReplayBufferRequest {
return StartReplayBufferRequest{
_request{
ID_: getMessageID(),
Type_: "StartReplayBuffer",
err: make(chan error, 1),
},
make(chan StartReplayBufferResponse, 1),
}
}
// Send sends the request.
func (r *StartReplayBufferRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp StartReplayBufferResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r StartReplayBufferRequest) Receive() (StartReplayBufferResponse, error) {
if !r.sent {
return StartReplayBufferResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartReplayBufferResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartReplayBufferResponse{}, err
case <-time.After(receiveTimeout):
return StartReplayBufferResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r StartReplayBufferRequest) SendReceive(c *Client) (StartReplayBufferResponse, error) {
if err := r.Send(c); err != nil {
return StartReplayBufferResponse{}, err
}
return r.Receive()
}
// StartReplayBufferResponse : Response for StartReplayBufferRequest.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startreplaybuffer
type StartReplayBufferResponse struct {
_response `json:",squash"`
}
// StopReplayBufferRequest : Stop recording into the Replay Buffer.
// Will return an `error` if the Replay Buffer is not active.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#stopreplaybuffer
type StopReplayBufferRequest struct {
_request `json:",squash"`
response chan StopReplayBufferResponse
}
// NewStopReplayBufferRequest returns a new StopReplayBufferRequest.
func NewStopReplayBufferRequest() StopReplayBufferRequest {
return StopReplayBufferRequest{
_request{
ID_: getMessageID(),
Type_: "StopReplayBuffer",
err: make(chan error, 1),
},
make(chan StopReplayBufferResponse, 1),
}
}
// Send sends the request.
func (r *StopReplayBufferRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp StopReplayBufferResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r StopReplayBufferRequest) Receive() (StopReplayBufferResponse, error) {
if !r.sent {
return StopReplayBufferResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StopReplayBufferResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StopReplayBufferResponse{}, err
case <-time.After(receiveTimeout):
return StopReplayBufferResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r StopReplayBufferRequest) SendReceive(c *Client) (StopReplayBufferResponse, error) {
if err := r.Send(c); err != nil {
return StopReplayBufferResponse{}, err
}
return r.Receive()
}
// StopReplayBufferResponse : Response for StopReplayBufferRequest.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#stopreplaybuffer
type StopReplayBufferResponse struct {
_response `json:",squash"`
}
// SaveReplayBufferRequest : Flush and save the contents of the Replay Buffer to disk
// This is
// basically the same as triggering the "Save Replay Buffer" hotkey.
// Will return an `error` if the Replay Buffer is not active.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#savereplaybuffer
type SaveReplayBufferRequest struct {
_request `json:",squash"`
response chan SaveReplayBufferResponse
}
// NewSaveReplayBufferRequest returns a new SaveReplayBufferRequest.
func NewSaveReplayBufferRequest() SaveReplayBufferRequest {
return SaveReplayBufferRequest{
_request{
ID_: getMessageID(),
Type_: "SaveReplayBuffer",
err: make(chan error, 1),
},
make(chan SaveReplayBufferResponse, 1),
}
}
// Send sends the request.
func (r *SaveReplayBufferRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SaveReplayBufferResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SaveReplayBufferRequest) Receive() (SaveReplayBufferResponse, error) {
if !r.sent {
return SaveReplayBufferResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SaveReplayBufferResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SaveReplayBufferResponse{}, err
case <-time.After(receiveTimeout):
return SaveReplayBufferResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SaveReplayBufferRequest) SendReceive(c *Client) (SaveReplayBufferResponse, error) {
if err := r.Send(c); err != nil {
return SaveReplayBufferResponse{}, err
}
return r.Receive()
}
// SaveReplayBufferResponse : Response for SaveReplayBufferRequest.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#savereplaybuffer
type SaveReplayBufferResponse struct {
_response `json:",squash"`
}

View File

@ -0,0 +1,282 @@
package obsws
import (
"errors"
"time"
)
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// SetCurrentSceneCollectionRequest : Change the active scene collection.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setcurrentscenecollection
type SetCurrentSceneCollectionRequest struct {
// Name of the desired scene collection.
// Required: Yes.
ScName string `json:"sc-name"`
_request `json:",squash"`
response chan SetCurrentSceneCollectionResponse
}
// NewSetCurrentSceneCollectionRequest returns a new SetCurrentSceneCollectionRequest.
func NewSetCurrentSceneCollectionRequest(scName string) SetCurrentSceneCollectionRequest {
return SetCurrentSceneCollectionRequest{
scName,
_request{
ID_: getMessageID(),
Type_: "SetCurrentSceneCollection",
err: make(chan error, 1),
},
make(chan SetCurrentSceneCollectionResponse, 1),
}
}
// Send sends the request.
func (r *SetCurrentSceneCollectionRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetCurrentSceneCollectionResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetCurrentSceneCollectionRequest) Receive() (SetCurrentSceneCollectionResponse, error) {
if !r.sent {
return SetCurrentSceneCollectionResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetCurrentSceneCollectionResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetCurrentSceneCollectionResponse{}, err
case <-time.After(receiveTimeout):
return SetCurrentSceneCollectionResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetCurrentSceneCollectionRequest) SendReceive(c *Client) (SetCurrentSceneCollectionResponse, error) {
if err := r.Send(c); err != nil {
return SetCurrentSceneCollectionResponse{}, err
}
return r.Receive()
}
// SetCurrentSceneCollectionResponse : Response for SetCurrentSceneCollectionRequest.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setcurrentscenecollection
type SetCurrentSceneCollectionResponse struct {
_response `json:",squash"`
}
// GetCurrentSceneCollectionRequest : Get the name of the current scene collection.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getcurrentscenecollection
type GetCurrentSceneCollectionRequest struct {
_request `json:",squash"`
response chan GetCurrentSceneCollectionResponse
}
// NewGetCurrentSceneCollectionRequest returns a new GetCurrentSceneCollectionRequest.
func NewGetCurrentSceneCollectionRequest() GetCurrentSceneCollectionRequest {
return GetCurrentSceneCollectionRequest{
_request{
ID_: getMessageID(),
Type_: "GetCurrentSceneCollection",
err: make(chan error, 1),
},
make(chan GetCurrentSceneCollectionResponse, 1),
}
}
// Send sends the request.
func (r *GetCurrentSceneCollectionRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetCurrentSceneCollectionResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetCurrentSceneCollectionRequest) Receive() (GetCurrentSceneCollectionResponse, error) {
if !r.sent {
return GetCurrentSceneCollectionResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetCurrentSceneCollectionResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetCurrentSceneCollectionResponse{}, err
case <-time.After(receiveTimeout):
return GetCurrentSceneCollectionResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetCurrentSceneCollectionRequest) SendReceive(c *Client) (GetCurrentSceneCollectionResponse, error) {
if err := r.Send(c); err != nil {
return GetCurrentSceneCollectionResponse{}, err
}
return r.Receive()
}
// GetCurrentSceneCollectionResponse : Response for GetCurrentSceneCollectionRequest.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getcurrentscenecollection
type GetCurrentSceneCollectionResponse struct {
// Name of the currently active scene collection.
// Required: Yes.
ScName string `json:"sc-name"`
_response `json:",squash"`
}
// ListSceneCollectionsRequest : List available scene collections.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#listscenecollections
type ListSceneCollectionsRequest struct {
_request `json:",squash"`
response chan ListSceneCollectionsResponse
}
// NewListSceneCollectionsRequest returns a new ListSceneCollectionsRequest.
func NewListSceneCollectionsRequest() ListSceneCollectionsRequest {
return ListSceneCollectionsRequest{
_request{
ID_: getMessageID(),
Type_: "ListSceneCollections",
err: make(chan error, 1),
},
make(chan ListSceneCollectionsResponse, 1),
}
}
// Send sends the request.
func (r *ListSceneCollectionsRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp ListSceneCollectionsResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r ListSceneCollectionsRequest) Receive() (ListSceneCollectionsResponse, error) {
if !r.sent {
return ListSceneCollectionsResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return ListSceneCollectionsResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return ListSceneCollectionsResponse{}, err
case <-time.After(receiveTimeout):
return ListSceneCollectionsResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r ListSceneCollectionsRequest) SendReceive(c *Client) (ListSceneCollectionsResponse, error) {
if err := r.Send(c); err != nil {
return ListSceneCollectionsResponse{}, err
}
return r.Receive()
}
// ListSceneCollectionsResponse : Response for ListSceneCollectionsRequest.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#listscenecollections
type ListSceneCollectionsResponse struct {
// Scene collections list.
// Required: Yes.
SceneCollections interface{} `json:"scene-collections"`
// Required: Yes.
SceneCollectionsStar string `json:"scene-collections.*."`
_response `json:",squash"`
}

View File

@ -0,0 +1,878 @@
package obsws
import (
"errors"
"time"
)
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// GetSceneItemPropertiesRequest : Gets the scene specific properties of the specified source item.
//
// Since obs-websocket version: 4.3.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getsceneitemproperties
type GetSceneItemPropertiesRequest struct {
// the name of the scene that the source item belongs to.
// Defaults to the current scene.
// Required: No.
SceneName string `json:"scene-name"`
// The name of the source.
// Required: Yes.
Item string `json:"item"`
_request `json:",squash"`
response chan GetSceneItemPropertiesResponse
}
// NewGetSceneItemPropertiesRequest returns a new GetSceneItemPropertiesRequest.
func NewGetSceneItemPropertiesRequest(
sceneName string,
item string,
) GetSceneItemPropertiesRequest {
return GetSceneItemPropertiesRequest{
sceneName,
item,
_request{
ID_: getMessageID(),
Type_: "GetSceneItemProperties",
err: make(chan error, 1),
},
make(chan GetSceneItemPropertiesResponse, 1),
}
}
// Send sends the request.
func (r *GetSceneItemPropertiesRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetSceneItemPropertiesResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetSceneItemPropertiesRequest) Receive() (GetSceneItemPropertiesResponse, error) {
if !r.sent {
return GetSceneItemPropertiesResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetSceneItemPropertiesResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetSceneItemPropertiesResponse{}, err
case <-time.After(receiveTimeout):
return GetSceneItemPropertiesResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetSceneItemPropertiesRequest) SendReceive(c *Client) (GetSceneItemPropertiesResponse, error) {
if err := r.Send(c); err != nil {
return GetSceneItemPropertiesResponse{}, err
}
return r.Receive()
}
// GetSceneItemPropertiesResponse : Response for GetSceneItemPropertiesRequest.
//
// Since obs-websocket version: 4.3.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getsceneitemproperties
type GetSceneItemPropertiesResponse struct {
// The name of the source.
// Required: Yes.
Name string `json:"name"`
// The x position of the source from the left.
// Required: Yes.
PositionX int `json:"position.x"`
// The y position of the source from the top.
// Required: Yes.
PositionY int `json:"position.y"`
// The point on the source that the item is manipulated from.
// Required: Yes.
PositionAlignment int `json:"position.alignment"`
// The clockwise rotation of the item in degrees around the point of alignment.
// Required: Yes.
Rotation float64 `json:"rotation"`
// The x-scale factor of the source.
// Required: Yes.
ScaleX float64 `json:"scale.x"`
// The y-scale factor of the source.
// Required: Yes.
ScaleY float64 `json:"scale.y"`
// The number of pixels cropped off the top of the source before scaling.
// Required: Yes.
CropTop int `json:"crop.top"`
// The number of pixels cropped off the right of the source before scaling.
// Required: Yes.
CropRight int `json:"crop.right"`
// The number of pixels cropped off the bottom of the source before scaling.
// Required: Yes.
CropBottom int `json:"crop.bottom"`
// The number of pixels cropped off the left of the source before scaling.
// Required: Yes.
CropLeft int `json:"crop.left"`
// If the source is visible.
// Required: Yes.
Visible bool `json:"visible"`
// Type of bounding box.
// Required: Yes.
BoundsType string `json:"bounds.type"`
// Alignment of the bounding box.
// Required: Yes.
BoundsAlignment int `json:"bounds.alignment"`
// Width of the bounding box.
// Required: Yes.
BoundsX float64 `json:"bounds.x"`
// Height of the bounding box.
// Required: Yes.
BoundsY float64 `json:"bounds.y"`
_response `json:",squash"`
}
// SetSceneItemPropertiesRequest : Sets the scene specific properties of a source
// Unspecified properties will remain unchanged.
//
// Since obs-websocket version: 4.3.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setsceneitemproperties
type SetSceneItemPropertiesRequest struct {
// the name of the scene that the source item belongs to.
// Defaults to the current scene.
// Required: No.
SceneName string `json:"scene-name"`
// The name of the source.
// Required: Yes.
Item string `json:"item"`
// The new x position of the source.
// Required: Yes.
PositionX int `json:"position.x"`
// The new y position of the source.
// Required: Yes.
PositionY int `json:"position.y"`
// The new alignment of the source.
// Required: Yes.
PositionAlignment int `json:"position.alignment"`
// The new clockwise rotation of the item in degrees.
// Required: Yes.
Rotation float64 `json:"rotation"`
// The new x scale of the item.
// Required: Yes.
ScaleX float64 `json:"scale.x"`
// The new y scale of the item.
// Required: Yes.
ScaleY float64 `json:"scale.y"`
// The new amount of pixels cropped off the top of the source before scaling.
// Required: Yes.
CropTop int `json:"crop.top"`
// The new amount of pixels cropped off the bottom of the source before scaling.
// Required: Yes.
CropBottom int `json:"crop.bottom"`
// The new amount of pixels cropped off the left of the source before scaling.
// Required: Yes.
CropLeft int `json:"crop.left"`
// The new amount of pixels cropped off the right of the source before scaling.
// Required: Yes.
CropRight int `json:"crop.right"`
// The new visibility of the source.
// 'true' shows source, 'false' hides source.
// Required: Yes.
Visible bool `json:"visible"`
// The new bounds type of the source.
// Required: Yes.
BoundsType string `json:"bounds.type"`
// The new alignment of the bounding box.
// (0-2, 4-6, 8-10).
// Required: Yes.
BoundsAlignment int `json:"bounds.alignment"`
// The new width of the bounding box.
// Required: Yes.
BoundsX float64 `json:"bounds.x"`
// The new height of the bounding box.
// Required: Yes.
BoundsY float64 `json:"bounds.y"`
_request `json:",squash"`
response chan SetSceneItemPropertiesResponse
}
// NewSetSceneItemPropertiesRequest returns a new SetSceneItemPropertiesRequest.
func NewSetSceneItemPropertiesRequest(
sceneName string,
item string,
positionX int,
positionY int,
positionAlignment int,
rotation float64,
scaleX float64,
scaleY float64,
cropTop int,
cropBottom int,
cropLeft int,
cropRight int,
visible bool,
boundsType string,
boundsAlignment int,
boundsX float64,
boundsY float64,
) SetSceneItemPropertiesRequest {
return SetSceneItemPropertiesRequest{
sceneName,
item,
positionX,
positionY,
positionAlignment,
rotation,
scaleX,
scaleY,
cropTop,
cropBottom,
cropLeft,
cropRight,
visible,
boundsType,
boundsAlignment,
boundsX,
boundsY,
_request{
ID_: getMessageID(),
Type_: "SetSceneItemProperties",
err: make(chan error, 1),
},
make(chan SetSceneItemPropertiesResponse, 1),
}
}
// Send sends the request.
func (r *SetSceneItemPropertiesRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetSceneItemPropertiesResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetSceneItemPropertiesRequest) Receive() (SetSceneItemPropertiesResponse, error) {
if !r.sent {
return SetSceneItemPropertiesResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetSceneItemPropertiesResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetSceneItemPropertiesResponse{}, err
case <-time.After(receiveTimeout):
return SetSceneItemPropertiesResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetSceneItemPropertiesRequest) SendReceive(c *Client) (SetSceneItemPropertiesResponse, error) {
if err := r.Send(c); err != nil {
return SetSceneItemPropertiesResponse{}, err
}
return r.Receive()
}
// SetSceneItemPropertiesResponse : Response for SetSceneItemPropertiesRequest.
//
// Since obs-websocket version: 4.3.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setsceneitemproperties
type SetSceneItemPropertiesResponse struct {
_response `json:",squash"`
}
// ResetSceneItemRequest : Reset a scene item.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#resetsceneitem
type ResetSceneItemRequest struct {
// Name of the scene the source belongs to.
// Defaults to the current scene.
// Required: No.
SceneName string `json:"scene-name"`
// Name of the source item.
// Required: Yes.
Item string `json:"item"`
_request `json:",squash"`
response chan ResetSceneItemResponse
}
// NewResetSceneItemRequest returns a new ResetSceneItemRequest.
func NewResetSceneItemRequest(
sceneName string,
item string,
) ResetSceneItemRequest {
return ResetSceneItemRequest{
sceneName,
item,
_request{
ID_: getMessageID(),
Type_: "ResetSceneItem",
err: make(chan error, 1),
},
make(chan ResetSceneItemResponse, 1),
}
}
// Send sends the request.
func (r *ResetSceneItemRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp ResetSceneItemResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r ResetSceneItemRequest) Receive() (ResetSceneItemResponse, error) {
if !r.sent {
return ResetSceneItemResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return ResetSceneItemResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return ResetSceneItemResponse{}, err
case <-time.After(receiveTimeout):
return ResetSceneItemResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r ResetSceneItemRequest) SendReceive(c *Client) (ResetSceneItemResponse, error) {
if err := r.Send(c); err != nil {
return ResetSceneItemResponse{}, err
}
return r.Receive()
}
// ResetSceneItemResponse : Response for ResetSceneItemRequest.
//
// Since obs-websocket version: 4.2.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#resetsceneitem
type ResetSceneItemResponse struct {
_response `json:",squash"`
}
// SetSceneItemRenderRequest : Show or hide a specified source item in a specified scene.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setsceneitemrender
type SetSceneItemRenderRequest struct {
// Scene item name in the specified scene.
// Required: Yes.
Source string `json:"source"`
// true = shown ; false = hidden.
// Required: Yes.
Render bool `json:"render"`
// Name of the scene where the source resides.
// Defaults to the currently active scene.
// Required: No.
SceneName string `json:"scene-name"`
_request `json:",squash"`
response chan SetSceneItemRenderResponse
}
// NewSetSceneItemRenderRequest returns a new SetSceneItemRenderRequest.
func NewSetSceneItemRenderRequest(
source string,
render bool,
sceneName string,
) SetSceneItemRenderRequest {
return SetSceneItemRenderRequest{
source,
render,
sceneName,
_request{
ID_: getMessageID(),
Type_: "SetSceneItemRender",
err: make(chan error, 1),
},
make(chan SetSceneItemRenderResponse, 1),
}
}
// Send sends the request.
func (r *SetSceneItemRenderRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetSceneItemRenderResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetSceneItemRenderRequest) Receive() (SetSceneItemRenderResponse, error) {
if !r.sent {
return SetSceneItemRenderResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetSceneItemRenderResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetSceneItemRenderResponse{}, err
case <-time.After(receiveTimeout):
return SetSceneItemRenderResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetSceneItemRenderRequest) SendReceive(c *Client) (SetSceneItemRenderResponse, error) {
if err := r.Send(c); err != nil {
return SetSceneItemRenderResponse{}, err
}
return r.Receive()
}
// SetSceneItemRenderResponse : Response for SetSceneItemRenderRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setsceneitemrender
type SetSceneItemRenderResponse struct {
_response `json:",squash"`
}
// SetSceneItemPositionRequest : Sets the coordinates of a specified source item.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setsceneitemposition
type SetSceneItemPositionRequest struct {
// The name of the scene that the source item belongs to.
// Defaults to the current scene.
// Required: No.
SceneName string `json:"scene-name"`
// The name of the source item.
// Required: Yes.
Item string `json:"item"`
// X coordinate.
// Required: Yes.
X float64 `json:"x"`
// Y coordinate.
// Required: Yes.
Y float64 `json:"y"`
_request `json:",squash"`
response chan SetSceneItemPositionResponse
}
// NewSetSceneItemPositionRequest returns a new SetSceneItemPositionRequest.
func NewSetSceneItemPositionRequest(
sceneName string,
item string,
x float64,
y float64,
) SetSceneItemPositionRequest {
return SetSceneItemPositionRequest{
sceneName,
item,
x,
y,
_request{
ID_: getMessageID(),
Type_: "SetSceneItemPosition",
err: make(chan error, 1),
},
make(chan SetSceneItemPositionResponse, 1),
}
}
// Send sends the request.
func (r *SetSceneItemPositionRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetSceneItemPositionResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetSceneItemPositionRequest) Receive() (SetSceneItemPositionResponse, error) {
if !r.sent {
return SetSceneItemPositionResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetSceneItemPositionResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetSceneItemPositionResponse{}, err
case <-time.After(receiveTimeout):
return SetSceneItemPositionResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetSceneItemPositionRequest) SendReceive(c *Client) (SetSceneItemPositionResponse, error) {
if err := r.Send(c); err != nil {
return SetSceneItemPositionResponse{}, err
}
return r.Receive()
}
// SetSceneItemPositionResponse : Response for SetSceneItemPositionRequest.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setsceneitemposition
type SetSceneItemPositionResponse struct {
_response `json:",squash"`
}
// SetSceneItemTransformRequest : Set the transform of the specified source item.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setsceneitemtransform
type SetSceneItemTransformRequest struct {
// The name of the scene that the source item belongs to.
// Defaults to the current scene.
// Required: No.
SceneName string `json:"scene-name"`
// The name of the source item.
// Required: Yes.
Item string `json:"item"`
// Width scale factor.
// Required: Yes.
XScale float64 `json:"x-scale"`
// Height scale factor.
// Required: Yes.
YScale float64 `json:"y-scale"`
// Source item rotation (in degrees).
// Required: Yes.
Rotation float64 `json:"rotation"`
_request `json:",squash"`
response chan SetSceneItemTransformResponse
}
// NewSetSceneItemTransformRequest returns a new SetSceneItemTransformRequest.
func NewSetSceneItemTransformRequest(
sceneName string,
item string,
xScale float64,
yScale float64,
rotation float64,
) SetSceneItemTransformRequest {
return SetSceneItemTransformRequest{
sceneName,
item,
xScale,
yScale,
rotation,
_request{
ID_: getMessageID(),
Type_: "SetSceneItemTransform",
err: make(chan error, 1),
},
make(chan SetSceneItemTransformResponse, 1),
}
}
// Send sends the request.
func (r *SetSceneItemTransformRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetSceneItemTransformResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetSceneItemTransformRequest) Receive() (SetSceneItemTransformResponse, error) {
if !r.sent {
return SetSceneItemTransformResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetSceneItemTransformResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetSceneItemTransformResponse{}, err
case <-time.After(receiveTimeout):
return SetSceneItemTransformResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetSceneItemTransformRequest) SendReceive(c *Client) (SetSceneItemTransformResponse, error) {
if err := r.Send(c); err != nil {
return SetSceneItemTransformResponse{}, err
}
return r.Receive()
}
// SetSceneItemTransformResponse : Response for SetSceneItemTransformRequest.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setsceneitemtransform
type SetSceneItemTransformResponse struct {
_response `json:",squash"`
}
// SetSceneItemCropRequest : Sets the crop coordinates of the specified source item.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setsceneitemcrop
type SetSceneItemCropRequest struct {
// the name of the scene that the source item belongs to.
// Defaults to the current scene.
// Required: No.
SceneName string `json:"scene-name"`
// The name of the source.
// Required: Yes.
Item string `json:"item"`
// Pixel position of the top of the source item.
// Required: Yes.
Top int `json:"top"`
// Pixel position of the bottom of the source item.
// Required: Yes.
Bottom int `json:"bottom"`
// Pixel position of the left of the source item.
// Required: Yes.
Left int `json:"left"`
// Pixel position of the right of the source item.
// Required: Yes.
Right int `json:"right"`
_request `json:",squash"`
response chan SetSceneItemCropResponse
}
// NewSetSceneItemCropRequest returns a new SetSceneItemCropRequest.
func NewSetSceneItemCropRequest(
sceneName string,
item string,
top int,
bottom int,
left int,
right int,
) SetSceneItemCropRequest {
return SetSceneItemCropRequest{
sceneName,
item,
top,
bottom,
left,
right,
_request{
ID_: getMessageID(),
Type_: "SetSceneItemCrop",
err: make(chan error, 1),
},
make(chan SetSceneItemCropResponse, 1),
}
}
// Send sends the request.
func (r *SetSceneItemCropRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetSceneItemCropResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetSceneItemCropRequest) Receive() (SetSceneItemCropResponse, error) {
if !r.sent {
return SetSceneItemCropResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetSceneItemCropResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetSceneItemCropResponse{}, err
case <-time.After(receiveTimeout):
return SetSceneItemCropResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetSceneItemCropRequest) SendReceive(c *Client) (SetSceneItemCropResponse, error) {
if err := r.Send(c); err != nil {
return SetSceneItemCropResponse{}, err
}
return r.Receive()
}
// SetSceneItemCropResponse : Response for SetSceneItemCropRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setsceneitemcrop
type SetSceneItemCropResponse struct {
_response `json:",squash"`
}

286
obsws/requests_scenes.go Normal file
View File

@ -0,0 +1,286 @@
package obsws
import (
"errors"
"time"
)
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// SetCurrentSceneRequest : Switch to the specified scene.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setcurrentscene
type SetCurrentSceneRequest struct {
// Name of the scene to switch to.
// Required: Yes.
SceneName string `json:"scene-name"`
_request `json:",squash"`
response chan SetCurrentSceneResponse
}
// NewSetCurrentSceneRequest returns a new SetCurrentSceneRequest.
func NewSetCurrentSceneRequest(sceneName string) SetCurrentSceneRequest {
return SetCurrentSceneRequest{
sceneName,
_request{
ID_: getMessageID(),
Type_: "SetCurrentScene",
err: make(chan error, 1),
},
make(chan SetCurrentSceneResponse, 1),
}
}
// Send sends the request.
func (r *SetCurrentSceneRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetCurrentSceneResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetCurrentSceneRequest) Receive() (SetCurrentSceneResponse, error) {
if !r.sent {
return SetCurrentSceneResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetCurrentSceneResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetCurrentSceneResponse{}, err
case <-time.After(receiveTimeout):
return SetCurrentSceneResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetCurrentSceneRequest) SendReceive(c *Client) (SetCurrentSceneResponse, error) {
if err := r.Send(c); err != nil {
return SetCurrentSceneResponse{}, err
}
return r.Receive()
}
// SetCurrentSceneResponse : Response for SetCurrentSceneRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setcurrentscene
type SetCurrentSceneResponse struct {
_response `json:",squash"`
}
// GetCurrentSceneRequest : Get the current scene's name and source items.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getcurrentscene
type GetCurrentSceneRequest struct {
_request `json:",squash"`
response chan GetCurrentSceneResponse
}
// NewGetCurrentSceneRequest returns a new GetCurrentSceneRequest.
func NewGetCurrentSceneRequest() GetCurrentSceneRequest {
return GetCurrentSceneRequest{
_request{
ID_: getMessageID(),
Type_: "GetCurrentScene",
err: make(chan error, 1),
},
make(chan GetCurrentSceneResponse, 1),
}
}
// Send sends the request.
func (r *GetCurrentSceneRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetCurrentSceneResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetCurrentSceneRequest) Receive() (GetCurrentSceneResponse, error) {
if !r.sent {
return GetCurrentSceneResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetCurrentSceneResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetCurrentSceneResponse{}, err
case <-time.After(receiveTimeout):
return GetCurrentSceneResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetCurrentSceneRequest) SendReceive(c *Client) (GetCurrentSceneResponse, error) {
if err := r.Send(c); err != nil {
return GetCurrentSceneResponse{}, err
}
return r.Receive()
}
// GetCurrentSceneResponse : Response for GetCurrentSceneRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getcurrentscene
type GetCurrentSceneResponse struct {
// Name of the currently active scene.
// Required: Yes.
Name string `json:"name"`
// Ordered list of the current scene's source items.
// Required: Yes.
Sources []map[string]interface{} `json:"sources"`
_response `json:",squash"`
}
// GetSceneListRequest : Get a list of scenes in the currently active profile.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getscenelist
type GetSceneListRequest struct {
_request `json:",squash"`
response chan GetSceneListResponse
}
// NewGetSceneListRequest returns a new GetSceneListRequest.
func NewGetSceneListRequest() GetSceneListRequest {
return GetSceneListRequest{
_request{
ID_: getMessageID(),
Type_: "GetSceneList",
err: make(chan error, 1),
},
make(chan GetSceneListResponse, 1),
}
}
// Send sends the request.
func (r *GetSceneListRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetSceneListResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetSceneListRequest) Receive() (GetSceneListResponse, error) {
if !r.sent {
return GetSceneListResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetSceneListResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetSceneListResponse{}, err
case <-time.After(receiveTimeout):
return GetSceneListResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetSceneListRequest) SendReceive(c *Client) (GetSceneListResponse, error) {
if err := r.Send(c); err != nil {
return GetSceneListResponse{}, err
}
return r.Receive()
}
// GetSceneListResponse : Response for GetSceneListRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getscenelist
type GetSceneListResponse struct {
// Name of the currently active scene.
// Required: Yes.
CurrentScene string `json:"current-scene"`
// Ordered list of the current profile's scenes (See `[GetCurrentScene](#getcurrentscene)` for more information).
// Required: Yes.
Scenes []map[string]interface{} `json:"scenes"`
_response `json:",squash"`
}

2784
obsws/requests_sources.go Normal file

File diff suppressed because it is too large Load Diff

757
obsws/requests_streaming.go Normal file
View File

@ -0,0 +1,757 @@
package obsws
import (
"errors"
"time"
)
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// GetStreamingStatusRequest : Get current streaming and recording status.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getstreamingstatus
type GetStreamingStatusRequest struct {
_request `json:",squash"`
response chan GetStreamingStatusResponse
}
// NewGetStreamingStatusRequest returns a new GetStreamingStatusRequest.
func NewGetStreamingStatusRequest() GetStreamingStatusRequest {
return GetStreamingStatusRequest{
_request{
ID_: getMessageID(),
Type_: "GetStreamingStatus",
err: make(chan error, 1),
},
make(chan GetStreamingStatusResponse, 1),
}
}
// Send sends the request.
func (r *GetStreamingStatusRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetStreamingStatusResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetStreamingStatusRequest) Receive() (GetStreamingStatusResponse, error) {
if !r.sent {
return GetStreamingStatusResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetStreamingStatusResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetStreamingStatusResponse{}, err
case <-time.After(receiveTimeout):
return GetStreamingStatusResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetStreamingStatusRequest) SendReceive(c *Client) (GetStreamingStatusResponse, error) {
if err := r.Send(c); err != nil {
return GetStreamingStatusResponse{}, err
}
return r.Receive()
}
// GetStreamingStatusResponse : Response for GetStreamingStatusRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getstreamingstatus
type GetStreamingStatusResponse struct {
// Current streaming status.
// Required: Yes.
Streaming bool `json:"streaming"`
// Current recording status.
// Required: Yes.
Recording bool `json:"recording"`
// Time elapsed since streaming started (only present if currently streaming).
// Required: No.
StreamTimecode string `json:"stream-timecode"`
// Time elapsed since recording started (only present if currently recording).
// Required: No.
RecTimecode string `json:"rec-timecode"`
// Always false.
// Retrocompatibility with OBSRemote.
// Required: Yes.
PreviewOnly bool `json:"preview-only"`
_response `json:",squash"`
}
// StartStopStreamingRequest : Toggle streaming on or off.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startstopstreaming
type StartStopStreamingRequest struct {
_request `json:",squash"`
response chan StartStopStreamingResponse
}
// NewStartStopStreamingRequest returns a new StartStopStreamingRequest.
func NewStartStopStreamingRequest() StartStopStreamingRequest {
return StartStopStreamingRequest{
_request{
ID_: getMessageID(),
Type_: "StartStopStreaming",
err: make(chan error, 1),
},
make(chan StartStopStreamingResponse, 1),
}
}
// Send sends the request.
func (r *StartStopStreamingRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp StartStopStreamingResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r StartStopStreamingRequest) Receive() (StartStopStreamingResponse, error) {
if !r.sent {
return StartStopStreamingResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartStopStreamingResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartStopStreamingResponse{}, err
case <-time.After(receiveTimeout):
return StartStopStreamingResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r StartStopStreamingRequest) SendReceive(c *Client) (StartStopStreamingResponse, error) {
if err := r.Send(c); err != nil {
return StartStopStreamingResponse{}, err
}
return r.Receive()
}
// StartStopStreamingResponse : Response for StartStopStreamingRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startstopstreaming
type StartStopStreamingResponse struct {
_response `json:",squash"`
}
// StartStreamingRequest : Start streaming.
// Will return an `error` if streaming is already active.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startstreaming
type StartStreamingRequest struct {
// Special stream configuration.
// Please note: these won't be saved to OBS' configuration.
// Required: No.
Stream map[string]interface{} `json:"stream"`
// If specified ensures the type of stream matches the given type (usually 'rtmp_custom' or 'rtmp_common').
// If the currently configured stream type does not match the given stream type, all settings must be specified in the `settings` object or an error will occur when starting the stream.
// Required: No.
StreamType string `json:"stream.type"`
// Adds the given object parameters as encoded query string parameters to the 'key' of the RTMP stream.
// Used to pass data to the RTMP service about the streaming.
// May be any String, Numeric, or Boolean field.
// Required: No.
StreamMetadata map[string]interface{} `json:"stream.metadata"`
// Settings for the stream.
// Required: No.
StreamSettings map[string]interface{} `json:"stream.settings"`
// The publish URL.
// Required: No.
StreamSettingsServer string `json:"stream.settings.server"`
// The publish key of the stream.
// Required: No.
StreamSettingsKey string `json:"stream.settings.key"`
// Indicates whether authentication should be used when connecting to the streaming server.
// Required: No.
StreamSettingsUseAuth bool `json:"stream.settings.use-auth"`
// If authentication is enabled, the username for the streaming server.
// Ignored if `use-auth` is not set to `true`.
// Required: No.
StreamSettingsUsername string `json:"stream.settings.username"`
// If authentication is enabled, the password for the streaming server.
// Ignored if `use-auth` is not set to `true`.
// Required: No.
StreamSettingsPassword string `json:"stream.settings.password"`
_request `json:",squash"`
response chan StartStreamingResponse
}
// NewStartStreamingRequest returns a new StartStreamingRequest.
func NewStartStreamingRequest(
stream map[string]interface{},
streamType string,
streamMetadata map[string]interface{},
streamSettings map[string]interface{},
streamSettingsServer string,
streamSettingsKey string,
streamSettingsUseAuth bool,
streamSettingsUsername string,
streamSettingsPassword string,
) StartStreamingRequest {
return StartStreamingRequest{
stream,
streamType,
streamMetadata,
streamSettings,
streamSettingsServer,
streamSettingsKey,
streamSettingsUseAuth,
streamSettingsUsername,
streamSettingsPassword,
_request{
ID_: getMessageID(),
Type_: "StartStreaming",
err: make(chan error, 1),
},
make(chan StartStreamingResponse, 1),
}
}
// Send sends the request.
func (r *StartStreamingRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp StartStreamingResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r StartStreamingRequest) Receive() (StartStreamingResponse, error) {
if !r.sent {
return StartStreamingResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartStreamingResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StartStreamingResponse{}, err
case <-time.After(receiveTimeout):
return StartStreamingResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r StartStreamingRequest) SendReceive(c *Client) (StartStreamingResponse, error) {
if err := r.Send(c); err != nil {
return StartStreamingResponse{}, err
}
return r.Receive()
}
// StartStreamingResponse : Response for StartStreamingRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#startstreaming
type StartStreamingResponse struct {
_response `json:",squash"`
}
// StopStreamingRequest : Stop streaming.
// Will return an `error` if streaming is not active.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#stopstreaming
type StopStreamingRequest struct {
_request `json:",squash"`
response chan StopStreamingResponse
}
// NewStopStreamingRequest returns a new StopStreamingRequest.
func NewStopStreamingRequest() StopStreamingRequest {
return StopStreamingRequest{
_request{
ID_: getMessageID(),
Type_: "StopStreaming",
err: make(chan error, 1),
},
make(chan StopStreamingResponse, 1),
}
}
// Send sends the request.
func (r *StopStreamingRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp StopStreamingResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r StopStreamingRequest) Receive() (StopStreamingResponse, error) {
if !r.sent {
return StopStreamingResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StopStreamingResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return StopStreamingResponse{}, err
case <-time.After(receiveTimeout):
return StopStreamingResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r StopStreamingRequest) SendReceive(c *Client) (StopStreamingResponse, error) {
if err := r.Send(c); err != nil {
return StopStreamingResponse{}, err
}
return r.Receive()
}
// StopStreamingResponse : Response for StopStreamingRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#stopstreaming
type StopStreamingResponse struct {
_response `json:",squash"`
}
// SetStreamSettingsRequest : Sets one or more attributes of the current streaming server settings
// Any options not passed will remain unchanged
// Returns the updated settings in response
// If 'type' is different than the current streaming service type, all settings are required
// Returns the full settings of the stream (the same as GetStreamSettings).
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setstreamsettings
type SetStreamSettingsRequest struct {
// The type of streaming service configuration, usually `rtmp_custom` or `rtmp_common`.
// Required: Yes.
StreamType string `json:"type"`
// The actual settings of the stream.
// Required: Yes.
Settings map[string]interface{} `json:"settings"`
// The publish URL.
// Required: No.
SettingsServer string `json:"settings.server"`
// The publish key.
// Required: No.
SettingsKey string `json:"settings.key"`
// Indicates whether authentication should be used when connecting to the streaming server.
// Required: No.
SettingsUseAuth bool `json:"settings.use-auth"`
// The username for the streaming service.
// Required: No.
SettingsUsername string `json:"settings.username"`
// The password for the streaming service.
// Required: No.
SettingsPassword string `json:"settings.password"`
// Persist the settings to disk.
// Required: Yes.
Save bool `json:"save"`
_request `json:",squash"`
response chan SetStreamSettingsResponse
}
// NewSetStreamSettingsRequest returns a new SetStreamSettingsRequest.
func NewSetStreamSettingsRequest(
_type string,
settings map[string]interface{},
settingsServer string,
settingsKey string,
settingsUseAuth bool,
settingsUsername string,
settingsPassword string,
save bool,
) SetStreamSettingsRequest {
return SetStreamSettingsRequest{
_type,
settings,
settingsServer,
settingsKey,
settingsUseAuth,
settingsUsername,
settingsPassword,
save,
_request{
ID_: getMessageID(),
Type_: "SetStreamSettings",
err: make(chan error, 1),
},
make(chan SetStreamSettingsResponse, 1),
}
}
// Send sends the request.
func (r *SetStreamSettingsRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetStreamSettingsResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetStreamSettingsRequest) Receive() (SetStreamSettingsResponse, error) {
if !r.sent {
return SetStreamSettingsResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetStreamSettingsResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetStreamSettingsResponse{}, err
case <-time.After(receiveTimeout):
return SetStreamSettingsResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetStreamSettingsRequest) SendReceive(c *Client) (SetStreamSettingsResponse, error) {
if err := r.Send(c); err != nil {
return SetStreamSettingsResponse{}, err
}
return r.Receive()
}
// SetStreamSettingsResponse : Response for SetStreamSettingsRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setstreamsettings
type SetStreamSettingsResponse struct {
_response `json:",squash"`
}
// GetStreamSettingsRequest : Get the current streaming server settings.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getstreamsettings
type GetStreamSettingsRequest struct {
_request `json:",squash"`
response chan GetStreamSettingsResponse
}
// NewGetStreamSettingsRequest returns a new GetStreamSettingsRequest.
func NewGetStreamSettingsRequest() GetStreamSettingsRequest {
return GetStreamSettingsRequest{
_request{
ID_: getMessageID(),
Type_: "GetStreamSettings",
err: make(chan error, 1),
},
make(chan GetStreamSettingsResponse, 1),
}
}
// Send sends the request.
func (r *GetStreamSettingsRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetStreamSettingsResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetStreamSettingsRequest) Receive() (GetStreamSettingsResponse, error) {
if !r.sent {
return GetStreamSettingsResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetStreamSettingsResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetStreamSettingsResponse{}, err
case <-time.After(receiveTimeout):
return GetStreamSettingsResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetStreamSettingsRequest) SendReceive(c *Client) (GetStreamSettingsResponse, error) {
if err := r.Send(c); err != nil {
return GetStreamSettingsResponse{}, err
}
return r.Receive()
}
// GetStreamSettingsResponse : Response for GetStreamSettingsRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getstreamsettings
type GetStreamSettingsResponse struct {
// The type of streaming service configuration.
// Possible values: 'rtmp_custom' or 'rtmp_common'.
// Required: Yes.
Type string `json:"type"`
// Stream settings object.
// Required: Yes.
Settings map[string]interface{} `json:"settings"`
// The publish URL.
// Required: Yes.
SettingsServer string `json:"settings.server"`
// The publish key of the stream.
// Required: Yes.
SettingsKey string `json:"settings.key"`
// Indicates whether authentication should be used when connecting to the streaming server.
// Required: Yes.
SettingsUseAuth bool `json:"settings.use-auth"`
// The username to use when accessing the streaming server.
// Only present if `use-auth` is `true`.
// Required: Yes.
SettingsUsername string `json:"settings.username"`
// The password to use when accessing the streaming server.
// Only present if `use-auth` is `true`.
// Required: Yes.
SettingsPassword string `json:"settings.password"`
_response `json:",squash"`
}
// SaveStreamSettingsRequest : Save the current streaming server settings to disk.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#savestreamsettings
type SaveStreamSettingsRequest struct {
_request `json:",squash"`
response chan SaveStreamSettingsResponse
}
// NewSaveStreamSettingsRequest returns a new SaveStreamSettingsRequest.
func NewSaveStreamSettingsRequest() SaveStreamSettingsRequest {
return SaveStreamSettingsRequest{
_request{
ID_: getMessageID(),
Type_: "SaveStreamSettings",
err: make(chan error, 1),
},
make(chan SaveStreamSettingsResponse, 1),
}
}
// Send sends the request.
func (r *SaveStreamSettingsRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SaveStreamSettingsResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SaveStreamSettingsRequest) Receive() (SaveStreamSettingsResponse, error) {
if !r.sent {
return SaveStreamSettingsResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SaveStreamSettingsResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SaveStreamSettingsResponse{}, err
case <-time.After(receiveTimeout):
return SaveStreamSettingsResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SaveStreamSettingsRequest) SendReceive(c *Client) (SaveStreamSettingsResponse, error) {
if err := r.Send(c); err != nil {
return SaveStreamSettingsResponse{}, err
}
return r.Receive()
}
// SaveStreamSettingsResponse : Response for SaveStreamSettingsRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#savestreamsettings
type SaveStreamSettingsResponse struct {
_response `json:",squash"`
}

View File

@ -0,0 +1,650 @@
package obsws
import (
"errors"
"time"
)
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// GetStudioModeStatusRequest : Indicates if Studio Mode is currently enabled.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getstudiomodestatus
type GetStudioModeStatusRequest struct {
_request `json:",squash"`
response chan GetStudioModeStatusResponse
}
// NewGetStudioModeStatusRequest returns a new GetStudioModeStatusRequest.
func NewGetStudioModeStatusRequest() GetStudioModeStatusRequest {
return GetStudioModeStatusRequest{
_request{
ID_: getMessageID(),
Type_: "GetStudioModeStatus",
err: make(chan error, 1),
},
make(chan GetStudioModeStatusResponse, 1),
}
}
// Send sends the request.
func (r *GetStudioModeStatusRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetStudioModeStatusResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetStudioModeStatusRequest) Receive() (GetStudioModeStatusResponse, error) {
if !r.sent {
return GetStudioModeStatusResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetStudioModeStatusResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetStudioModeStatusResponse{}, err
case <-time.After(receiveTimeout):
return GetStudioModeStatusResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetStudioModeStatusRequest) SendReceive(c *Client) (GetStudioModeStatusResponse, error) {
if err := r.Send(c); err != nil {
return GetStudioModeStatusResponse{}, err
}
return r.Receive()
}
// GetStudioModeStatusResponse : Response for GetStudioModeStatusRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getstudiomodestatus
type GetStudioModeStatusResponse struct {
// Indicates if Studio Mode is enabled.
// Required: Yes.
StudioMode bool `json:"studio-mode"`
_response `json:",squash"`
}
// GetPreviewSceneRequest : Get the name of the currently previewed scene and its list of sources.
// Will return an `error` if Studio Mode is not enabled.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getpreviewscene
type GetPreviewSceneRequest struct {
_request `json:",squash"`
response chan GetPreviewSceneResponse
}
// NewGetPreviewSceneRequest returns a new GetPreviewSceneRequest.
func NewGetPreviewSceneRequest() GetPreviewSceneRequest {
return GetPreviewSceneRequest{
_request{
ID_: getMessageID(),
Type_: "GetPreviewScene",
err: make(chan error, 1),
},
make(chan GetPreviewSceneResponse, 1),
}
}
// Send sends the request.
func (r *GetPreviewSceneRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetPreviewSceneResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetPreviewSceneRequest) Receive() (GetPreviewSceneResponse, error) {
if !r.sent {
return GetPreviewSceneResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetPreviewSceneResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetPreviewSceneResponse{}, err
case <-time.After(receiveTimeout):
return GetPreviewSceneResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetPreviewSceneRequest) SendReceive(c *Client) (GetPreviewSceneResponse, error) {
if err := r.Send(c); err != nil {
return GetPreviewSceneResponse{}, err
}
return r.Receive()
}
// GetPreviewSceneResponse : Response for GetPreviewSceneRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getpreviewscene
type GetPreviewSceneResponse struct {
// The name of the active preview scene.
// Required: Yes.
Name string `json:"name"`
// Required: Yes.
Sources []map[string]interface{} `json:"sources"`
_response `json:",squash"`
}
// SetPreviewSceneRequest : Set the active preview scene.
// Will return an `error` if Studio Mode is not enabled.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setpreviewscene
type SetPreviewSceneRequest struct {
// The name of the scene to preview.
// Required: Yes.
SceneName string `json:"scene-name"`
_request `json:",squash"`
response chan SetPreviewSceneResponse
}
// NewSetPreviewSceneRequest returns a new SetPreviewSceneRequest.
func NewSetPreviewSceneRequest(sceneName string) SetPreviewSceneRequest {
return SetPreviewSceneRequest{
sceneName,
_request{
ID_: getMessageID(),
Type_: "SetPreviewScene",
err: make(chan error, 1),
},
make(chan SetPreviewSceneResponse, 1),
}
}
// Send sends the request.
func (r *SetPreviewSceneRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetPreviewSceneResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetPreviewSceneRequest) Receive() (SetPreviewSceneResponse, error) {
if !r.sent {
return SetPreviewSceneResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetPreviewSceneResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetPreviewSceneResponse{}, err
case <-time.After(receiveTimeout):
return SetPreviewSceneResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetPreviewSceneRequest) SendReceive(c *Client) (SetPreviewSceneResponse, error) {
if err := r.Send(c); err != nil {
return SetPreviewSceneResponse{}, err
}
return r.Receive()
}
// SetPreviewSceneResponse : Response for SetPreviewSceneRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setpreviewscene
type SetPreviewSceneResponse struct {
_response `json:",squash"`
}
// TransitionToProgramRequest : Transitions the currently previewed scene to the main output.
// Will return an `error` if Studio Mode is not enabled.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#transitiontoprogram
type TransitionToProgramRequest struct {
// Change the active transition before switching scenes.
// Defaults to the active transition.
// Required: No.
WithTransition map[string]interface{} `json:"with-transition"`
// Name of the transition.
// Required: Yes.
WithTransitionName string `json:"with-transition.name"`
// Transition duration (in milliseconds).
// Required: No.
WithTransitionDuration int `json:"with-transition.duration"`
_request `json:",squash"`
response chan TransitionToProgramResponse
}
// NewTransitionToProgramRequest returns a new TransitionToProgramRequest.
func NewTransitionToProgramRequest(
withTransition map[string]interface{},
withTransitionName string,
withTransitionDuration int,
) TransitionToProgramRequest {
return TransitionToProgramRequest{
withTransition,
withTransitionName,
withTransitionDuration,
_request{
ID_: getMessageID(),
Type_: "TransitionToProgram",
err: make(chan error, 1),
},
make(chan TransitionToProgramResponse, 1),
}
}
// Send sends the request.
func (r *TransitionToProgramRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp TransitionToProgramResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r TransitionToProgramRequest) Receive() (TransitionToProgramResponse, error) {
if !r.sent {
return TransitionToProgramResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return TransitionToProgramResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return TransitionToProgramResponse{}, err
case <-time.After(receiveTimeout):
return TransitionToProgramResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r TransitionToProgramRequest) SendReceive(c *Client) (TransitionToProgramResponse, error) {
if err := r.Send(c); err != nil {
return TransitionToProgramResponse{}, err
}
return r.Receive()
}
// TransitionToProgramResponse : Response for TransitionToProgramRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#transitiontoprogram
type TransitionToProgramResponse struct {
_response `json:",squash"`
}
// EnableStudioModeRequest : Enables Studio Mode.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#enablestudiomode
type EnableStudioModeRequest struct {
_request `json:",squash"`
response chan EnableStudioModeResponse
}
// NewEnableStudioModeRequest returns a new EnableStudioModeRequest.
func NewEnableStudioModeRequest() EnableStudioModeRequest {
return EnableStudioModeRequest{
_request{
ID_: getMessageID(),
Type_: "EnableStudioMode",
err: make(chan error, 1),
},
make(chan EnableStudioModeResponse, 1),
}
}
// Send sends the request.
func (r *EnableStudioModeRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp EnableStudioModeResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r EnableStudioModeRequest) Receive() (EnableStudioModeResponse, error) {
if !r.sent {
return EnableStudioModeResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return EnableStudioModeResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return EnableStudioModeResponse{}, err
case <-time.After(receiveTimeout):
return EnableStudioModeResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r EnableStudioModeRequest) SendReceive(c *Client) (EnableStudioModeResponse, error) {
if err := r.Send(c); err != nil {
return EnableStudioModeResponse{}, err
}
return r.Receive()
}
// EnableStudioModeResponse : Response for EnableStudioModeRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#enablestudiomode
type EnableStudioModeResponse struct {
_response `json:",squash"`
}
// DisableStudioModeRequest : Disables Studio Mode.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#disablestudiomode
type DisableStudioModeRequest struct {
_request `json:",squash"`
response chan DisableStudioModeResponse
}
// NewDisableStudioModeRequest returns a new DisableStudioModeRequest.
func NewDisableStudioModeRequest() DisableStudioModeRequest {
return DisableStudioModeRequest{
_request{
ID_: getMessageID(),
Type_: "DisableStudioMode",
err: make(chan error, 1),
},
make(chan DisableStudioModeResponse, 1),
}
}
// Send sends the request.
func (r *DisableStudioModeRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp DisableStudioModeResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r DisableStudioModeRequest) Receive() (DisableStudioModeResponse, error) {
if !r.sent {
return DisableStudioModeResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return DisableStudioModeResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return DisableStudioModeResponse{}, err
case <-time.After(receiveTimeout):
return DisableStudioModeResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r DisableStudioModeRequest) SendReceive(c *Client) (DisableStudioModeResponse, error) {
if err := r.Send(c); err != nil {
return DisableStudioModeResponse{}, err
}
return r.Receive()
}
// DisableStudioModeResponse : Response for DisableStudioModeRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#disablestudiomode
type DisableStudioModeResponse struct {
_response `json:",squash"`
}
// ToggleStudioModeRequest : Toggles Studio Mode.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#togglestudiomode
type ToggleStudioModeRequest struct {
_request `json:",squash"`
response chan ToggleStudioModeResponse
}
// NewToggleStudioModeRequest returns a new ToggleStudioModeRequest.
func NewToggleStudioModeRequest() ToggleStudioModeRequest {
return ToggleStudioModeRequest{
_request{
ID_: getMessageID(),
Type_: "ToggleStudioMode",
err: make(chan error, 1),
},
make(chan ToggleStudioModeResponse, 1),
}
}
// Send sends the request.
func (r *ToggleStudioModeRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp ToggleStudioModeResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r ToggleStudioModeRequest) Receive() (ToggleStudioModeResponse, error) {
if !r.sent {
return ToggleStudioModeResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return ToggleStudioModeResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return ToggleStudioModeResponse{}, err
case <-time.After(receiveTimeout):
return ToggleStudioModeResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r ToggleStudioModeRequest) SendReceive(c *Client) (ToggleStudioModeResponse, error) {
if err := r.Send(c); err != nil {
return ToggleStudioModeResponse{}, err
}
return r.Receive()
}
// ToggleStudioModeResponse : Response for ToggleStudioModeRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#togglestudiomode
type ToggleStudioModeResponse struct {
_response `json:",squash"`
}

View File

@ -0,0 +1,470 @@
package obsws
import (
"errors"
"time"
)
// This file is automatically generated.
// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py
// GetTransitionListRequest : List of all transitions available in the frontend's dropdown menu.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#gettransitionlist
type GetTransitionListRequest struct {
_request `json:",squash"`
response chan GetTransitionListResponse
}
// NewGetTransitionListRequest returns a new GetTransitionListRequest.
func NewGetTransitionListRequest() GetTransitionListRequest {
return GetTransitionListRequest{
_request{
ID_: getMessageID(),
Type_: "GetTransitionList",
err: make(chan error, 1),
},
make(chan GetTransitionListResponse, 1),
}
}
// Send sends the request.
func (r *GetTransitionListRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetTransitionListResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetTransitionListRequest) Receive() (GetTransitionListResponse, error) {
if !r.sent {
return GetTransitionListResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetTransitionListResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetTransitionListResponse{}, err
case <-time.After(receiveTimeout):
return GetTransitionListResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetTransitionListRequest) SendReceive(c *Client) (GetTransitionListResponse, error) {
if err := r.Send(c); err != nil {
return GetTransitionListResponse{}, err
}
return r.Receive()
}
// GetTransitionListResponse : Response for GetTransitionListRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#gettransitionlist
type GetTransitionListResponse struct {
// Name of the currently active transition.
// Required: Yes.
CurrentTransition string `json:"current-transition"`
// List of transitions.
// Required: Yes.
Transitions interface{} `json:"transitions"`
// Name of the transition.
// Required: Yes.
TransitionsName string `json:"transitions[].name"`
_response `json:",squash"`
}
// GetCurrentTransitionRequest : Get the name of the currently selected transition in the frontend's dropdown menu.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getcurrenttransition
type GetCurrentTransitionRequest struct {
_request `json:",squash"`
response chan GetCurrentTransitionResponse
}
// NewGetCurrentTransitionRequest returns a new GetCurrentTransitionRequest.
func NewGetCurrentTransitionRequest() GetCurrentTransitionRequest {
return GetCurrentTransitionRequest{
_request{
ID_: getMessageID(),
Type_: "GetCurrentTransition",
err: make(chan error, 1),
},
make(chan GetCurrentTransitionResponse, 1),
}
}
// Send sends the request.
func (r *GetCurrentTransitionRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetCurrentTransitionResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetCurrentTransitionRequest) Receive() (GetCurrentTransitionResponse, error) {
if !r.sent {
return GetCurrentTransitionResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetCurrentTransitionResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetCurrentTransitionResponse{}, err
case <-time.After(receiveTimeout):
return GetCurrentTransitionResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetCurrentTransitionRequest) SendReceive(c *Client) (GetCurrentTransitionResponse, error) {
if err := r.Send(c); err != nil {
return GetCurrentTransitionResponse{}, err
}
return r.Receive()
}
// GetCurrentTransitionResponse : Response for GetCurrentTransitionRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#getcurrenttransition
type GetCurrentTransitionResponse struct {
// Name of the selected transition.
// Required: Yes.
Name string `json:"name"`
// Transition duration (in milliseconds) if supported by the transition.
// Required: No.
Duration int `json:"duration"`
_response `json:",squash"`
}
// SetCurrentTransitionRequest : Set the active transition.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setcurrenttransition
type SetCurrentTransitionRequest struct {
// The name of the transition.
// Required: Yes.
TransitionName string `json:"transition-name"`
_request `json:",squash"`
response chan SetCurrentTransitionResponse
}
// NewSetCurrentTransitionRequest returns a new SetCurrentTransitionRequest.
func NewSetCurrentTransitionRequest(transitionName string) SetCurrentTransitionRequest {
return SetCurrentTransitionRequest{
transitionName,
_request{
ID_: getMessageID(),
Type_: "SetCurrentTransition",
err: make(chan error, 1),
},
make(chan SetCurrentTransitionResponse, 1),
}
}
// Send sends the request.
func (r *SetCurrentTransitionRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetCurrentTransitionResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetCurrentTransitionRequest) Receive() (SetCurrentTransitionResponse, error) {
if !r.sent {
return SetCurrentTransitionResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetCurrentTransitionResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetCurrentTransitionResponse{}, err
case <-time.After(receiveTimeout):
return SetCurrentTransitionResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetCurrentTransitionRequest) SendReceive(c *Client) (SetCurrentTransitionResponse, error) {
if err := r.Send(c); err != nil {
return SetCurrentTransitionResponse{}, err
}
return r.Receive()
}
// SetCurrentTransitionResponse : Response for SetCurrentTransitionRequest.
//
// Since obs-websocket version: 0.3.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#setcurrenttransition
type SetCurrentTransitionResponse struct {
_response `json:",squash"`
}
// SetTransitionDurationRequest : Set the duration of the currently selected transition if supported.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#settransitionduration
type SetTransitionDurationRequest struct {
// Desired duration of the transition (in milliseconds).
// Required: Yes.
Duration int `json:"duration"`
_request `json:",squash"`
response chan SetTransitionDurationResponse
}
// NewSetTransitionDurationRequest returns a new SetTransitionDurationRequest.
func NewSetTransitionDurationRequest(duration int) SetTransitionDurationRequest {
return SetTransitionDurationRequest{
duration,
_request{
ID_: getMessageID(),
Type_: "SetTransitionDuration",
err: make(chan error, 1),
},
make(chan SetTransitionDurationResponse, 1),
}
}
// Send sends the request.
func (r *SetTransitionDurationRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp SetTransitionDurationResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r SetTransitionDurationRequest) Receive() (SetTransitionDurationResponse, error) {
if !r.sent {
return SetTransitionDurationResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetTransitionDurationResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return SetTransitionDurationResponse{}, err
case <-time.After(receiveTimeout):
return SetTransitionDurationResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r SetTransitionDurationRequest) SendReceive(c *Client) (SetTransitionDurationResponse, error) {
if err := r.Send(c); err != nil {
return SetTransitionDurationResponse{}, err
}
return r.Receive()
}
// SetTransitionDurationResponse : Response for SetTransitionDurationRequest.
//
// Since obs-websocket version: 4.0.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#settransitionduration
type SetTransitionDurationResponse struct {
_response `json:",squash"`
}
// GetTransitionDurationRequest : Get the duration of the currently selected transition if supported.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#gettransitionduration
type GetTransitionDurationRequest struct {
_request `json:",squash"`
response chan GetTransitionDurationResponse
}
// NewGetTransitionDurationRequest returns a new GetTransitionDurationRequest.
func NewGetTransitionDurationRequest() GetTransitionDurationRequest {
return GetTransitionDurationRequest{
_request{
ID_: getMessageID(),
Type_: "GetTransitionDuration",
err: make(chan error, 1),
},
make(chan GetTransitionDurationResponse, 1),
}
}
// Send sends the request.
func (r *GetTransitionDurationRequest) Send(c *Client) error {
if r.sent {
return ErrAlreadySent
}
future, err := c.sendRequest(r)
if err != nil {
return err
}
r.sent = true
go func() {
m := <-future
var resp GetTransitionDurationResponse
if err = mapToStruct(m, &resp); err != nil {
r.err <- err
} else if resp.Status() != StatusOK {
r.err <- errors.New(resp.Error())
} else {
r.response <- resp
}
}()
return nil
}
// Receive waits for the response.
func (r GetTransitionDurationRequest) Receive() (GetTransitionDurationResponse, error) {
if !r.sent {
return GetTransitionDurationResponse{}, ErrNotSent
}
if receiveTimeout == 0 {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetTransitionDurationResponse{}, err
}
} else {
select {
case resp := <-r.response:
return resp, nil
case err := <-r.err:
return GetTransitionDurationResponse{}, err
case <-time.After(receiveTimeout):
return GetTransitionDurationResponse{}, ErrReceiveTimeout
}
}
}
// SendReceive sends the request then immediately waits for the response.
func (r GetTransitionDurationRequest) SendReceive(c *Client) (GetTransitionDurationResponse, error) {
if err := r.Send(c); err != nil {
return GetTransitionDurationResponse{}, err
}
return r.Receive()
}
// GetTransitionDurationResponse : Response for GetTransitionDurationRequest.
//
// Since obs-websocket version: 4.1.0.
//
// https://github.com/Palakis/obs-websocket/blob/4.3-maintenance/docs/generated/protocol.md#gettransitionduration
type GetTransitionDurationResponse struct {
// Duration of the current transition (in milliseconds).
// Required: Yes.
TransitionDuration int `json:"transition-duration"`
_response `json:",squash"`
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

56
plugin/manifest.json Normal file
View File

@ -0,0 +1,56 @@
{
"Actions": [
{
"Icon": "images/actions/replay_off",
"Name": "OBS Replay Toggle",
"States": [
{
"Image": "images/actions/replay_off",
"TitleAlignment": "bottom",
"FontSize": "16"
},
{
"Image": "images/actions/replay_on",
"TitleAlignment": "bottom",
"FontSize": "16"
}
],
"Tooltip": "Toggle OBS' Replay Recording",
"UUID": "tf.meow.obsreplay.replay_toggle",
"PropertyInspectorPath": "pi/index_pi.html"
},
{
"Icon": "images/actions/replay_save",
"Name": "OBS Replay Save",
"States": [
{
"Image": "images/actions/replay_save",
"TitleAlignment": "bottom",
"FontSize": "16"
}
],
"Tooltip": "Tell OBS to save a replay",
"UUID": "tf.meow.obsreplay.replay_save",
"PropertyInspectorPath": "pi/index_pi.html"
}
],
"Author": "Meow.tf",
"Category": "OBS Replay",
"CodePathWin": "replay.exe",
"Description": "Control OBS' Replays using StreamDeck.",
"Name": "OBS Replay",
"Icon": "images/pluginIcon",
"CategoryIcon": "images/pluginIcon",
"URL": "https://streamdeck.meow.tf/obsreplay",
"Version": "1.2.5",
"SDKVersion": 2,
"OS": [
{
"Platform": "windows",
"MinimumVersion": "10"
}
],
"Software": {
"MinimumVersion": "4.2"
}
}

BIN
plugin/pi/css/check.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

3
plugin/pi/css/check.svg Normal file
View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="10" viewBox="0 0 12 10">
<polygon fill="#FFF" points="7.2 7.5 7.2 -1.3 8.7 -1.3 8.6 9.1 2.7 8.7 2.7 7.2" transform="rotate(37 5.718 3.896)"/>
</svg>

After

Width:  |  Height:  |  Size: 210 B

1483
plugin/pi/css/sdpi.css Normal file

File diff suppressed because it is too large Load Diff

44
plugin/pi/index_pi.html Normal file
View File

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,minimal-ui,viewport-fit=cover">
<meta name=apple-mobile-web-app-capable content=yes>
<meta name=apple-mobile-web-app-status-bar-style content=black>
<title>Property Inspector Samples PI</title>
<link rel="stylesheet" href="css/sdpi.css">
<!--link rel="stylesheet"
media="screen and (max-width: 1025px)"
href="css/local.css" -->
</head>
<body>
<div class="sdpi-wrapper">
<div class="sdpi-item" id="host_container" title="IP or Hostname of the obs-websocket server">
<div class="sdpi-item-label">IP/Host</div>
<input class="sdpi-item-value" id="host" value="" placeholder="e.g. 192.168.61.1" required>
</div>
<div class="sdpi-item" id="port_container" title="Port of the obs-websocket server">
<div class="sdpi-item-label">Port</div>
<input class="sdpi-item-value" id="port" value="4444" placeholder="4444" required>
</div>
<div class="sdpi-item" id="password_container">
<div class="sdpi-item-label">Password</div>
<input type="password" id="password" class="sdpi-item-value" value="">
</div>
</div>
<!-- <script src="echomd.js"></script> -->
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="index_pi.js"></script>
</body>
</html>

324
plugin/pi/index_pi.js Normal file
View File

@ -0,0 +1,324 @@
// this is our global websocket, used to communicate from/to Stream Deck software
// and some info about our plugin, as sent by Stream Deck software
var websocket = null,
uuid = null,
actionInfo = {},
settings = {},
globalSettings = {},
isQT = navigator.appVersion.includes('QtWebEngine'); // 'oninput'; // change this, if you want interactive elements act on any change, or while they're modified
const websiteAction = 'tf.meow.remote.website';
function connectSocket (
inPort,
inUUID,
inMessageType,
inApplicationInfo,
inActionInfo
) {
connectElgatoStreamDeckSocket(
inPort,
inUUID,
inMessageType,
inApplicationInfo,
inActionInfo
);
}
function connectElgatoStreamDeckSocket (inPort, inUUID, inRegisterEvent, inInfo, inActionInfo) {
uuid = inUUID;
// please note: the incoming arguments are of type STRING, so
// in case of the inActionInfo, we must parse it into JSON first
actionInfo = JSON.parse(inActionInfo); // cache the info
inInfo = JSON.parse(inInfo);
websocket = new WebSocket('ws://localhost:' + inPort);
/** Since the PI doesn't have access to your OS native settings
* Stream Deck sends some color settings to PI
* We use these to adjust some styles (e.g. highlight-colors for checkboxes)
*/
addDynamicStyles(inInfo.colors, 'connectElgatoStreamDeckSocket');
/** let's see, if we have some settings */
settings = getPropFromString(actionInfo, 'payload.settings');
console.log(settings, actionInfo);
initPropertyInspector(5);
// if connection was established, the websocket sends
// an 'onopen' event, where we need to register our PI
websocket.onopen = function () {
var json = {
event: inRegisterEvent,
uuid: inUUID
};
websocket.send(JSON.stringify(json));
};
websocket.onmessage = function (evt) {
// Received message from Stream Deck
let jsonObj = JSON.parse(evt.data);
let event = jsonObj['event'];
console.log('Got event', event);
switch (event) {
case 'didReceiveGlobalSettings':
didReceiveGlobalSettings(jsonObj);
break;
}
};
}
function initPropertyInspector(initDelay) {
const action = actionInfo['action'];
$('[data-action="' + action + '"]').removeClass('hidden');
Object.keys(settings).forEach(function (item) {
let $item = $('#' + item),
value = settings[item];
switch ($item.attr('type')) {
case 'checkbox':
let itemVal = $item.attr('value');
if (itemVal == 'false' || itemVal == 'true') {
itemVal = (/^true$/i).test(itemVal);
}
if (itemVal === value) {
$item.prop('checked', true);
}
break;
default:
$item.val(value);
}
});
$('input').each(function() {
let $this = $(this),
id = $this.attr('id');
let $item = $this.closest('.sdpi-item');
$this.on('change', function() {
const type = $this.attr('type');
let val = $this.val();
switch (type) {
case 'checkbox':
// If unchecked, unset the setting
if (!this.checked) {
removeSetting(id);
return;
}
if (val == 'false' || val == 'true') {
val = (/^true$/i).test(val);
}
break;
case 'file':
const info = $item.find('.sdpi-file-info');
if (info) {
const s = decodeURIComponent($this.val().replace(/^C:\\fakepath\\/, '')).split('/').pop();
info.text(s.length > 28
? s.substr(0, 10)
+ '...'
+ s.substr(s.length - 10, s.length)
: s);
}
break;
}
updateSetting(id, val);
});
});
}
if (!isQT) {
document.addEventListener('DOMContentLoaded', function () {
initPropertyInspector(100);
});
}
/** Stream Deck software passes system-highlight color information
* to Property Inspector. Here we 'inject' the CSS styles into the DOM
* when we receive this information. */
function addDynamicStyles (clrs, fromWhere) {
const node = document.getElementById('#sdpi-dynamic-styles') || document.createElement('style');
if (!clrs.mouseDownColor) clrs.mouseDownColor = fadeColor(clrs.highlightColor, -100);
const clr = clrs.highlightColor.slice(0, 7);
const clr1 = fadeColor(clr, 100);
const clr2 = fadeColor(clr, 60);
const metersActiveColor = fadeColor(clr, -60);
node.setAttribute('id', 'sdpi-dynamic-styles');
node.innerHTML = `
input[type="radio"]:checked + label span,
input[type="checkbox"]:checked + label span {
background-color: ${clrs.highlightColor};
}
input[type="radio"]:active:checked + label span,
input[type="radio"]:active + label span,
input[type="checkbox"]:active:checked + label span,
input[type="checkbox"]:active + label span {
background-color: ${clrs.mouseDownColor};
}
input[type="radio"]:active + label span,
input[type="checkbox"]:active + label span {
background-color: ${clrs.buttonPressedBorderColor};
}
td.selected,
td.selected:hover,
li.selected:hover,
li.selected {
color: white;
background-color: ${clrs.highlightColor};
}
.sdpi-file-label > label:active,
.sdpi-file-label.file:active,
label.sdpi-file-label:active,
label.sdpi-file-info:active,
input[type="file"]::-webkit-file-upload-button:active,
button:active {
background-color: ${clrs.buttonPressedBackgroundColor};
color: ${clrs.buttonPressedTextColor};
border-color: ${clrs.buttonPressedBorderColor};
}
::-webkit-progress-value,
meter::-webkit-meter-optimum-value {
background: linear-gradient(${clr2}, ${clr1} 20%, ${clr} 45%, ${clr} 55%, ${clr2})
}
::-webkit-progress-value:active,
meter::-webkit-meter-optimum-value:active {
background: linear-gradient(${clr}, ${clr2} 20%, ${metersActiveColor} 45%, ${metersActiveColor} 55%, ${clr})
}
`;
document.body.appendChild(node);
};
/** UTILITIES */
/** get a JSON property from a (dot-separated) string
* Works on nested JSON, e.g.:
* jsn = {
* propA: 1,
* propB: 2,
* propC: {
* subA: 3,
* subB: {
* testA: 5,
* testB: 'Hello'
* }
* }
* }
* getPropFromString(jsn,'propC.subB.testB') will return 'Hello';
*/
const getPropFromString = (jsn, str, sep = '.') => {
const arr = str.split(sep);
return arr.reduce((obj, key) =>
(obj && obj.hasOwnProperty(key)) ? obj[key] : undefined, jsn);
};
/*
Quick utility to lighten or darken a color (doesn't take color-drifting, etc. into account)
Usage:
fadeColor('#061261', 100); // will lighten the color
fadeColor('#200867'), -100); // will darken the color
*/
function fadeColor (col, amt) {
const min = Math.min, max = Math.max;
const num = parseInt(col.replace(/#/g, ''), 16);
const r = min(255, max((num >> 16) + amt, 0));
const g = min(255, max((num & 0x0000FF) + amt, 0));
const b = min(255, max(((num >> 8) & 0x00FF) + amt, 0));
return '#' + (g | (b << 8) | (r << 16)).toString(16).padStart(6, 0);
}
function updateSetting(setting, value) {
if (!settings) {
settings = {};
}
settings[setting] = value;
setSettings(settings);
}
function removeSetting(setting) {
if (!settings) {
settings = {};
}
delete settings[setting];
setSettings(settings);
}
function setSettings(settings) {
let json = {
"event": "setSettings",
"context": uuid,
"payload": settings
};
if (websocket) {
websocket.send(JSON.stringify(json));
}
}
function updateGlobalSetting(id, val) {
globalSettings[id] = val;
setGlobalSettings(globalSettings);
}
function getGlobalSettings() {
let json = {
"event": "getGlobalSettings",
"context": uuid
};
if (websocket) {
websocket.send(JSON.stringify(json));
}
}
function setGlobalSettings(settings) {
let json = {
"event": "setGlobalSettings",
"context": uuid,
"payload": settings
};
if (websocket) {
websocket.send(JSON.stringify(json));
}
}
function didReceiveGlobalSettings(obj) {
globalSettings = getPropFromString(obj, 'payload.settings');
// Load defaults for fields not set
Object.keys(globalSettings).forEach(function(item) {
if (!(item in settings)) {
$('#' + item).val(globalSettings[item]);
}
});
}
function isAction(action) {
return actionInfo['action'] === action;
}

256
replay.go Normal file
View File

@ -0,0 +1,256 @@
package main
import (
"github.com/valyala/fastjson"
"log"
"meow.tf/streamdeck/obs-replay/obsws"
"meow.tf/streamdeck/sdk"
"strconv"
"sync"
)
const (
actionReplayToggle = "tf.meow.obsreplay.replay_toggle"
actionReplaySave = "tf.meow.obsreplay.replay_save"
)
var (
contextMutex sync.RWMutex
clientMutex sync.RWMutex
stateMutex sync.RWMutex
clients = make(map[string]*obsws.Client)
contexts = make(map[string]string)
cachedStates = make(map[string]int)
)
func replayToggle(action, context string, payload *fastjson.Value, deviceId string) {
c := clientForContext(context)
if c == nil {
sdk.ShowAlert(context)
return
}
req := obsws.NewStartStopReplayBufferRequest()
err := req.Send(c)
if err != nil {
sdk.ShowAlert(context)
return
}
sdk.ShowOk(context)
}
func replaySave(action, context string, payload *fastjson.Value, deviceId string) {
c := clientForContext(context)
if c == nil {
sdk.ShowAlert(context)
return
}
req := obsws.NewSaveReplayBufferRequest()
if err := req.Send(c); err != nil {
sdk.ShowAlert(context)
return
}
sdk.ShowOk(context)
}
func clientForContext(context string) *obsws.Client {
contextMutex.RLock()
key, exists := contexts[context]
contextMutex.RUnlock()
if !exists {
return nil
}
clientMutex.RLock()
c, exists := clients[key]
clientMutex.RUnlock()
if !exists {
return nil
}
return c
}
func onWillAppear(e *sdk.WillAppearEvent) {
settings := e.Payload.Get("settings")
if settings != nil {
host := sdk.JsonStringValue(settings, "host")
port := settings.GetInt("port")
password := sdk.JsonStringValue(settings, "password")
key := checkClient(host, port, password)
if key == "" {
return
}
contextMutex.Lock()
contexts[e.Context] = key
contextMutex.Unlock()
stateMutex.RLock()
if state, ok := cachedStates[key]; ok {
sdk.SetState(e.Context, state)
}
stateMutex.RUnlock()
}
}
func checkClient(host string, port int, password string) string {
if port == 0 {
port = 4444
}
key := host + ":" + strconv.Itoa(port)
clientMutex.RLock()
client, ok := clients[key]
clientMutex.RUnlock()
if !ok {
client = &obsws.Client{Host: host, Port: port, Password: password}
err := client.Connect()
if err != nil {
return ""
}
client.AddEventHandler("StreamStatus", streamStatusUpdate(key))
client.AddEventHandler("ReplayStarted", loopContextState(key, 1))
client.AddEventHandler("ReplayStopped", loopContextState(key, 0))
clientMutex.Lock()
clients[key] = client
clientMutex.Unlock()
}
return key
}
func streamStatusUpdate(key string) func(obsws.Event) {
return func(e obsws.Event) {
evt := e.(obsws.StreamStatusEvent)
state := 0
if evt.Replay {
state = 1
}
loopContextState(key, state)
}
}
func loopContextState(key string, state int) func(obsws.Event) {
stateMutex.Lock()
cachedStates[key] = state
stateMutex.Unlock()
return func(event obsws.Event) {
contextMutex.RLock()
defer contextMutex.RUnlock()
for ctx, ctxKey := range contexts {
if ctxKey == key {
sdk.SetState(ctx, state)
}
}
}
}
func onWillDisappear(e *sdk.WillDisappearEvent) {
contextMutex.Lock()
defer contextMutex.Unlock()
// replayToggleContexts
key, ok := contexts[e.Context]
delete(contexts, e.Context)
if !ok {
return
}
for _, k := range contexts {
if k == key {
return
}
}
clientMutex.Lock()
clients[key].Disconnect()
delete(clients, key)
clientMutex.Unlock()
}
func onSettingsReceived(e *sdk.ReceiveSettingsEvent) {
var host, password string
host = sdk.JsonStringValue(e.Settings, "host")
port := e.Settings.GetInt("port")
password = sdk.JsonStringValue(e.Settings, "password")
if port == 0 {
port = 4444
}
key := checkClient(host, port, password)
if key == "" {
return
}
contextMutex.Lock()
contexts[e.Context] = key
contextMutex.Unlock()
stateMutex.RLock()
if state, ok := cachedStates[key]; ok {
sdk.SetState(e.Context, state)
}
stateMutex.RUnlock()
}
func main() {
sdk.RegisterAction(actionReplayToggle, replayToggle)
sdk.RegisterAction(actionReplaySave, replaySave)
sdk.AddHandler(onWillAppear)
sdk.AddHandler(onWillDisappear)
sdk.AddHandler(onSettingsReceived)
// Open and connect the SDK
err := sdk.Open()
if err != nil {
log.Fatalln(err)
}
defer cleanupSockets()
// Wait until the socket is closed, or SIGTERM/SIGINT is received
sdk.Wait()
}
func cleanupSockets() {
clientMutex.RLock()
defer clientMutex.RUnlock()
for _, client := range clients {
client.Disconnect()
}
}

21
replay_test.go Normal file
View File

@ -0,0 +1,21 @@
package main
import (
"meow.tf/streamdeck/obs-replay/obsws"
"testing"
)
func Test_ReplayStatus(t *testing.T) {
c := &obsws.Client{Host: "localhost", Port: 4444}
if err := c.Connect(); err != nil {
t.Fatal(err)
}
c.AddEventHandler("StreamStatus", func(e obsws.Event) {
// Make sure to assert the actual event type.
t.Log("status:", e.(obsws.StreamStatusEvent).Replay)
})
<- make(chan struct{})
}