requests

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Conn is the backing websocket connection to the OBS websockets
	// server. It's exported to pass the underlying connection to each
	// category subclient. You shouldn't worry about this.
	Conn *websocket.Conn

	IncomingResponses chan json.RawMessage
}

Client represents a client to an OBS websockets server, used for requests.

func (*Client) Disconnect

func (c *Client) Disconnect() error

Disconnect sends a message to the OBS websockets server to close the client's open connection. You don't really have to do this as any connections should close when your program terminates or interrupts. But here's a function anyways.

func (*Client) SendRequest

func (c *Client) SendRequest(params Params, response 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 can just read the next response from our channel. This works fine in a single-threaded context, and the message IDs of both the sent request and response should match.

In a concurrent context, this isn't necessarily true, but since gorilla/websocket doesn't handle concurrency anyways, who cares? We could technically add a mutex in between sending our request and reading from the channel, but ehh...

Interestingly, it does seem thread-safe if I use a totally different connection, in that connection A won't get a response from OBS for a request from connection B. So, message IDs must be unique per client? More interestingly, events appear to be broadcast to every client, maybe because they have no associated message ID?

type Params

type Params interface {
	GetRequestType() string
	SetRequestType(string)
	GetMessageID() string
	SetMessageID(string)

	// The name of the actual request, i.e. "Abc" for "AbcParams". Used to
	// set the RequestType.
	Name() string
}

Params describes the behavior for any params-like object. Used to abstract the functionality of any request that embeds ParamsBasic within their fields.

type ParamsBasic

type ParamsBasic struct {
	RequestType string `json:"request-type"`
	MessageID   string `json:"message-id"`
}

ParamsBasic represents common parameters for any request.

func (*ParamsBasic) GetMessageID

func (o *ParamsBasic) GetMessageID() string

GetMessageID does what it says.

func (*ParamsBasic) GetRequestType

func (o *ParamsBasic) GetRequestType() string

GetRequestType does what it says.

func (*ParamsBasic) SetMessageID

func (o *ParamsBasic) SetMessageID(x string)

SetMessageID does what it says.

func (*ParamsBasic) SetRequestType

func (o *ParamsBasic) SetRequestType(x string)

SetRequestType does what it says.

type Response

type Response interface {
	GetMessageID() string
	GetStatus() string
	GetError() string
}

Response describes the behavior for any response-like object. Used to abstract the functionality of any request's response that embeds ResponseBasic within their fields.

type ResponseBasic

type ResponseBasic struct {
	MessageID string `json:"message-id"`
	Status    string `json:"status"`
	Error     string `json:"error"`
}

ResponseBasic represents common fields on any returned response.

func (*ResponseBasic) GetError

func (o *ResponseBasic) GetError() string

GetError does what it says.

func (*ResponseBasic) GetMessageID

func (o *ResponseBasic) GetMessageID() string

GetMessageID does what it says.

func (*ResponseBasic) GetStatus

func (o *ResponseBasic) GetStatus() string

GetStatus does what it says.

Jump to

Keyboard shortcuts

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