Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var LibraryVersion = func() string { bi, ok := debug.ReadBuildInfo() if !ok { return "unknown" } for _, dep := range bi.Deps { if dep.Path == lib { return strings.TrimPrefix(dep.Version, "v") } } return "unknown" }()
var ProtocolVersion = "5.2.3"
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // See [Client.Listen] for more information. IncomingEvents chan any // contains filtered or unexported fields }
Client represents a client to an OBS websockets server.
func New ¶
New creates and configures a client to interact with the OBS websockets server. It also opens up a connection, so be sure to check the error.
func (*Client) Disconnect ¶ added in v0.9.0
Disconnect sends a message to the OBS websocket server to close the client's open connection. You should defer a disconnection after creating your client to ensure the program doesn't leave any lingering connections open and potentially leak memory, e.g.:
client, err := goobs.New("localhost:4455", goobs.WithPassword("secret")) if err != nil { panic(err) } defer client.Disconnect()
func (*Client) Listen ¶ added in v0.9.0
Listen hooks into the incoming events from the server. You'll have to make type assertions to ensure you're getting the right events, e.g.:
client.Listen(func(event any) { switch val := event.(type) { case *events.InputVolumeChanged: // event i was looking for default: // other events } })
If looking for high volume events, make sure you've initialized the client with the appropriate subscriptions with WithEventSubscriptions.
type Option ¶
type Option func(*Client)
Option represents a functional option of a Client.
func WithDialer ¶ added in v0.8.0
WithDialer sets the underlying gorilla/websocket.Dialer should one want to customize things like the handshake timeout or TLS configuration. If this is not set, it'll use the provided gorilla/websocket.DefaultDialer.
func WithEventSubscriptions ¶ added in v0.9.0
WithEventSubscriptions specifies the events we'd like to subscribe to via Client.Listen. The value is a bitmask of any of the subscription values specified in subscriptions. By default, all event categories are subscribed, except for events marked as high volume. High volume events must be explicitly subscribed to.
func WithLogger ¶ added in v0.7.1
WithLogger sets the logger this library will use. See the logger.Logger interface. Should be compatible with most third-party loggers.
func WithRequestHeader ¶ added in v0.8.0
WithRequestHeader sets custom headers our client can send when trying to connect to the WebSockets server, allowing us specify the origin, subprotocols, or the user agent.
func WithResponseTimeout ¶ added in v0.8.0
WithResponseTimeout sets the time we're willing to wait to receive a response from the server for any request, before responding with an error. It's in milliseconds. The default timeout is 10 seconds.