api

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: Apache-2.0 Imports: 7 Imported by: 14

Documentation

Overview

Package api is the intermediary API between the top-level goobs client and the category-level subclients.

Nothing in this package should be of interest to a user.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// The time we're willing to wait to receive a response from the server.
	ResponseTimeout time.Duration

	// This client sends raw opcodes it got from the server to this channel.
	Opcodes chan opcodes.Opcode

	// Once the top-level has parsed the raw opcode, it sends the response
	// to this channel.
	IncomingResponses chan *opcodes.RequestResponse

	// Ya like logs?
	Log Logger
	// contains filtered or unexported fields
}

Client represents a minimal client to the OBS websocket server.

func (*Client) SendRequest

func (c *Client) SendRequest(requestBody Params, responseBody Response) error

SendRequest abstracts the logic every subclient uses to send a request and receive the corresponding response.

To get the response for a sent request, we simply read the next response off our incoming responses channel. This works fine in a single-threaded context, and the message IDs of both the sent request and response should match.

A request ID and response ID mismatch could happen if the server processes requests in a different order it received them (e.g. we should 1, then 2; but it processes 2, and then 1). In this case there'll be an error, so note the mutex lock and deferred unlock to prevent this from happening.

It should be noted multiple connections to the server are totally fine. Phrased differently, mesasge IDs are unique per client. Moreover, events will be broadcast to every client.

type Logger

type Logger interface{ Printf(string, ...any) }

Logger is a interface compatible with both the stdlib's logger and some third-party loggers.

type LoggerWithWrite

type LoggerWithWrite func([]byte) (int, error)

LoggerWithWrite helps us anonymously satisfy a Writer interface

func (LoggerWithWrite) Write

func (f LoggerWithWrite) Write(p []byte) (int, error)

type Params

type Params interface{ GetRequestName() string }

type Response added in v1.0.0

type Response interface {
	GetRaw() json.RawMessage
	// contains filtered or unexported methods
}

type ResponseCommon added in v1.0.0

type ResponseCommon struct {
	// contains filtered or unexported fields
}

func (*ResponseCommon) GetRaw added in v1.0.0

func (o *ResponseCommon) GetRaw() json.RawMessage

Jump to

Keyboard shortcuts

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