### Execute OBS Example with Environment Variables (Shell) Source: https://github.com/xaionaro-go/goobs/blob/main/docs/README.md Shows how to run an OBS example script by setting necessary environment variables like `OBS_HOST` and `SCENE_NAME`. This is useful for testing specific OBS configurations. ```shell ❯ OBS_HOST=$WINHOST:4455 SCENE_NAME=Scene SOURCE_NAME=Image go run _examples/test/main.go ``` -------------------------------- ### Get OBS Input List and Iterate (Go) Source: https://github.com/xaionaro-go/goobs/blob/main/docs/README.md Shows how to retrieve a list of all inputs currently configured in OBS using `client.Inputs.GetInputList()`. The example iterates through the response to print details of each input. ```go resp, _ := client.Inputs.GetInputList() for _, i := range resp.Inputs { fmt.Printf("%+v\n", i) } ``` -------------------------------- ### Example Output for OBS Studio Version Info (Console) Source: https://github.com/xaionaro-go/goobs/blob/main/README.md This is the expected console output when running the Go example code that connects to OBS Studio and retrieves version information. It shows the versions of OBS Studio, the server's WebSocket protocol, the client's WebSocket protocol, and the goobs library itself. ```console ❯ go run _examples/basic/main.go OBS Studio version: 30.2.2 Server protocol version: 5.5.2 Client protocol version: 5.5.3 Client library version: 1.5.1 ``` -------------------------------- ### Connect to OBS Studio and Get Version Info (Go) Source: https://github.com/xaionaro-go/goobs/blob/main/README.md This Go code snippet demonstrates how to connect to an OBS Studio WebSocket server, authenticate with a password, and retrieve version information for both OBS Studio and the WebSocket protocol. It requires the 'goobs' library and assumes OBS Studio is running on localhost:4455 with the specified password. ```go package main import ( "fmt" "github.com/andreykaipov/goobs" ) func main() { client, err := goobs.New("localhost:4455", goobs.WithPassword("goodpassword")) if err != nil { panic(err) } defer client.Disconnect() version, err := client.General.GetVersion() if err != nil { panic(err) } fmt.Printf("OBS Studio version: %s\n", version.ObsVersion) fmt.Printf("Server protocol version: %s\n", version.ObsWebSocketVersion) fmt.Printf("Client protocol version: %s\n", goobs.ProtocolVersion) fmt.Printf("Client library version: %s\n", goobs.LibraryVersion) } ``` -------------------------------- ### Inspect Specific OBS Scene Item Events with goobs Source: https://github.com/xaionaro-go/goobs/blob/main/docs/README.md This example expands on basic event listening by using type assertions within the `client.Listen` callback to specifically handle `SceneItemListReindexed` and `SceneItemEnableStateChanged` events. It demonstrates how to access detailed information about scene item reordering and visibility changes, providing insights into the OBS state. ```go client.Listen(func(event any) { switch e := event.(type) { case *events.SceneItemListReindexed: fmt.Printf("reindexed: %v\n", e.SceneName) for _, item := range e.SceneItems { fmt.Printf(" %+v\n", item) } case *events.SceneItemEnableStateChanged: fmt.Printf("visibility:\n") fmt.Printf(" %+v\n", e) default: fmt.Printf("unhandled: %T\n", event) } }) ``` -------------------------------- ### Run goobs Docker Container Source: https://github.com/xaionaro-go/goobs/blob/main/docker/README.md This command runs the goobs Docker container, exposing the OBS-WebSocket port (4455) and allowing headless control of OBS. It's the most basic way to start the service. ```console ❯ docker run --rm -it -p 4455:1234 ghcr.io/andreykaipov/goobs ``` -------------------------------- ### Streaming Controls Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Methods for managing the OBS stream, including starting, stopping, and sending captions. ```APIDOC ## POST /stream/start ### Description Starts the OBS stream. ### Method POST ### Endpoint `client.Stream.StartStream(...)` ### Response #### Success Response (200) - **status** (string) - Confirmation of stream start. ``` -------------------------------- ### Get and Set Scene Item Visibility with goobs Source: https://github.com/xaionaro-go/goobs/blob/main/docs/README.md This Go code snippet demonstrates how to retrieve a list of scene items for a given scene, find a specific source's ID by its name, and then control its visibility. It utilizes `GetSceneItemList` to fetch scene data and a helper function `setSourceVisibility` which calls `SetSceneItemEnabled` to toggle the source's visibility. Environment variables are used to specify the scene and source names. ```go sceneName := os.Getenv("SCENE_NAME") sourceName := os.Getenv("SOURCE_NAME") params := sceneitems.NewGetSceneItemListParams().WithSceneName(sceneName) sceneList, err := client.SceneItems.GetSceneItemList(params) if err != nil { panic(err) } // find the ID of our source, while hiding all others var sourceID int for _, item := range sceneList.SceneItems { if item.SourceName == sourceName { sourceID = item.SceneItemID } setSourceVisibility(sceneName, item.SceneItemID, false) } // then show our source setSourceVisibility(sceneName, sourceID, true) ``` ```go func setSourceVisibility(scene string, sourceID int, visible bool) { params := &sceneitems.SetSceneItemEnabledParams{ SceneName: &scene, SceneItemId: &sourceID, SceneItemEnabled: &visible, } _, err := client.SceneItems.SetSceneItemEnabled(params) ``` -------------------------------- ### Enable VNC in goobs Docker Container Source: https://github.com/xaionaro-go/goobs/blob/main/docker/README.md This command runs the goobs Docker container with VNC enabled, exposing the VNC port (5900). This allows remote graphical access to the OBS instance within the container for monitoring or manual setup. ```console ❯ docker run --rm -it -e vnc=1 -p 5900:5900 ghcr.io/andreykaipov/goobs ``` -------------------------------- ### Create OBS Input using Builder Pattern (Go) Source: https://github.com/xaionaro-go/goobs/blob/main/docs/README.md Demonstrates creating a new input (e.g., video capture) in OBS using the goobs client's builder pattern for parameters. It specifies scene name, input name, and input kind. ```go params := inputs.NewCreateInputParams(). WithSceneName("my scene"). WithInputName("new browser"). WithInputKind("dshow_input") resp, err := client.Inputs.CreateInput(params) ``` -------------------------------- ### Listen to OBS Events with goobs Source: https://github.com/xaionaro-go/goobs/blob/main/docs/README.md This snippet shows how to initialize a goobs client and listen for any events broadcast by the OBS server. It's a foundational step for understanding and reacting to changes within OBS. The `client.Listen` function takes a callback that receives events of type `any`, allowing for flexible event handling. ```go client.Listen(func(event any) { fmt.Printf("got event: %T\n", event) }) ``` -------------------------------- ### Listen for OBS Events via Channel (Go) Source: https://github.com/xaionaro-go/goobs/blob/main/docs/README.md Illustrates how to receive OBS events directly from the `client.IncomingEvents` channel. This provides an alternative to `client.Listen()` for processing events in real-time. ```go for _, event := range c.IncomingEvents { fmt.Printf("got event: %#v\n", event) } ``` -------------------------------- ### Run OBS Client with Memory Profiling (Shell) Source: https://github.com/xaionaro-go/goobs/blob/main/docs/README.md Demonstrates how to run OBS tests with memory profiling enabled using the `GOOBS_PROFILE` environment variable. The output can be analyzed with `go tool pprof` to identify memory leaks. ```shell ❯ GOOBS_PROFILE=memprofile=mem.out OBS_PORT=4455 go test -v -run=profile client_test.go ❯ go tool pprof -top -sample_index=inuse_space mem.out ``` -------------------------------- ### Manage Inputs and Audio with goobs Source: https://context7.com/xaionaro-go/goobs/llms.txt Shows how to list existing inputs, create new browser sources, and adjust audio volume levels using both builder patterns and struct initialization. ```go package main import ( "fmt" "log" "github.com/andreykaipov/goobs" "github.com/andreykaipov/goobs/api/requests/inputs" ) func main() { client, err := goobs.New("localhost:4455", goobs.WithPassword("your-password")) if err != nil { log.Fatal(err) } defer client.Disconnect() // List all inputs list, err := client.Inputs.GetInputList() if err != nil { log.Fatal(err) } fmt.Println("All inputs:") for _, input := range list.Inputs { fmt.Printf(" - %s (kind: %s)\n", input.InputName, input.InputKind) } // Create a new browser source input createParams := inputs.NewCreateInputParams(). WithSceneName("Scene"). WithInputName("My Browser"). WithInputKind("browser_source"). WithInputSettings(map[string]any{ "url": "https://example.com", "width": 1920, "height": 1080, }). WithSceneItemEnabled(true) resp, err := client.Inputs.CreateInput(createParams) if err != nil { log.Fatal(err) } fmt.Printf("Created input with UUID: %s, scene item ID: %d\n", resp.InputUuid, resp.SceneItemId) // Set input volume using builder pattern volumeParams := inputs.NewSetInputVolumeParams(). WithInputName("Desktop Audio"). WithInputVolumeMul(0.5) // 50% volume _, err = client.Inputs.SetInputVolume(volumeParams) if err != nil { fmt.Printf("Could not set volume: %s\n", err) } // Alternative: Set volume using direct struct initialization name := "Mic/Aux" volumeDb := -10.0 _, err = client.Inputs.SetInputVolume(&inputs.SetInputVolumeParams{ InputName: &name, InputVolumeDb: &volumeDb, }) if err != nil { fmt.Printf("Could not set mic volume: %s\n", err) } } ``` -------------------------------- ### Initialize goobs client Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Initializes a new goobs client instance to connect to an OBS WebSocket server. Requires the server address and authentication credentials. ```go client, err := goobs.New("localhost:4455", goobs.WithPassword("whatever")) ``` -------------------------------- ### Manage OBS Live Streaming with goobs Source: https://context7.com/xaionaro-go/goobs/llms.txt Demonstrates how to initialize a connection to OBS, check stream status, start/stop the stream, and monitor performance metrics. Requires a running OBS instance with WebSocket enabled. ```go package main import ( "fmt" "log" "time" "github.com/andreykaipov/goobs" ) func main() { client, err := goobs.New("localhost:4455", goobs.WithPassword("your-password")) if err != nil { log.Fatal(err) } defer client.Disconnect() // Check stream status status, err := client.Stream.GetStreamStatus() if err != nil { log.Fatal(err) } fmt.Printf("Stream active: %v\n", status.OutputActive) // Start streaming (ensure stream settings are configured in OBS) _, err = client.Stream.StartStream() if err != nil { log.Fatal(err) } fmt.Println("Stream started!") // Monitor stream for 10 seconds for i := 0; i < 5; i++ { time.Sleep(2 * time.Second) status, _ = client.Stream.GetStreamStatus() fmt.Printf("Duration: %s, Bytes: %.0f, Frames: %.0f, Dropped: %.0f\n", status.OutputTimecode, status.OutputBytes, status.OutputTotalFrames, status.OutputSkippedFrames) } // Stop streaming _, err = client.Stream.StopStream() if err != nil { log.Fatal(err) } fmt.Println("Stream stopped!") } ``` -------------------------------- ### Config module request mapping Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Demonstrates how to access configuration-related OBS requests through the client.Config sub-module. ```go client.Config.CreateProfile(...) client.Config.GetProfileList(...) client.Config.SetCurrentProfile(...) ``` -------------------------------- ### General module request mapping Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Demonstrates how to access general OBS utility requests through the client.General sub-module. ```go client.General.GetVersion(...) client.General.BroadcastCustomEvent(...) client.General.Sleep(...) ``` -------------------------------- ### Manage OBS Scenes Source: https://context7.com/xaionaro-go/goobs/llms.txt Shows how to list existing scenes, create a new scene, and switch the active program scene using the Scenes API client. ```go package main import ( "fmt" "log" "github.com/andreykaipov/goobs" "github.com/andreykaipov/goobs/api/requests/scenes" ) func main() { client, err := goobs.New("localhost:4455", goobs.WithPassword("your-password")) if err != nil { log.Fatal(err) } defer client.Disconnect() // Get list of all scenes sceneList, err := client.Scenes.GetSceneList() if err != nil { log.Fatal(err) } fmt.Printf("Current program scene: %s\n", sceneList.CurrentProgramSceneName) fmt.Println("Available scenes:") for _, scene := range sceneList.Scenes { fmt.Printf(" - %s (UUID: %s)\n", scene.SceneName, scene.SceneUuid) } // Create a new scene createParams := scenes.NewCreateSceneParams().WithSceneName("My New Scene") createResp, err := client.Scenes.CreateScene(createParams) if err != nil { log.Fatal(err) } fmt.Printf("Created scene with UUID: %s\n", createResp.SceneUuid) // Switch to a different scene switchParams := scenes.NewSetCurrentProgramSceneParams().WithSceneName("My New Scene") _, err = client.Scenes.SetCurrentProgramScene(switchParams) if err != nil { log.Fatal(err) } fmt.Println("Switched to 'My New Scene'") } ``` -------------------------------- ### Manage OBS Scene Transitions Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Provides methods to retrieve and modify scene transition settings, durations, and studio mode triggers. These methods are accessed via the client.Transitions interface. ```go client.Transitions.GetCurrentSceneTransition(params) client.Transitions.GetCurrentSceneTransitionCursor(params) client.Transitions.GetSceneTransitionList(params) client.Transitions.GetTransitionKindList(params) client.Transitions.SetCurrentSceneTransition(params) client.Transitions.SetCurrentSceneTransitionDuration(params) client.Transitions.SetCurrentSceneTransitionSettings(params) client.Transitions.SetTBarPosition(params) client.Transitions.TriggerStudioModeTransition(params) ``` -------------------------------- ### Media Inputs module request mapping Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Demonstrates how to access media input control requests through the client.MediaInputs sub-module. ```go client.MediaInputs.GetMediaInputStatus(...) client.MediaInputs.TriggerMediaInputAction(...) ``` -------------------------------- ### Connect to OBS WebSocket Server Source: https://context7.com/xaionaro-go/goobs/llms.txt Demonstrates how to initialize a connection to the OBS WebSocket server using the goobs client. It includes password authentication and retrieving version information from the server. ```go package main import ( "fmt" "log" "github.com/andreykaipov/goobs" ) func main() { // Connect to OBS WebSocket server with password authentication client, err := goobs.New("localhost:4455", goobs.WithPassword("your-password")) if err != nil { log.Fatal(err) } defer client.Disconnect() // Get OBS version information version, err := client.General.GetVersion() if err != nil { log.Fatal(err) } fmt.Printf("OBS Studio version: %s\n", version.ObsVersion) fmt.Printf("Server protocol version: %s\n", version.ObsWebSocketVersion) fmt.Printf("Client protocol version: %s\n", goobs.ProtocolVersion) fmt.Printf("Client library version: %s\n", goobs.LibraryVersion) } ``` -------------------------------- ### Inputs module request mapping Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Demonstrates how to access input-related OBS requests through the client.Inputs sub-module. ```go client.Inputs.CreateInput(...) client.Inputs.GetInputList(...) client.Inputs.SetInputMute(...) ``` -------------------------------- ### Control OBS UI and Dialogs Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Provides methods to interact with the OBS user interface, including monitor lists, studio mode status, and opening various input dialogs or projectors. These methods are accessed via the client.Ui interface. ```go client.Ui.GetMonitorList(params) client.Ui.GetStudioModeEnabled(params) client.Ui.OpenInputFiltersDialog(params) client.Ui.OpenInputInteractDialog(params) client.Ui.OpenInputPropertiesDialog(params) client.Ui.OpenSourceProjector(params) client.Ui.OpenVideoMixProjector(params) client.Ui.SetStudioModeEnabled(params) ``` -------------------------------- ### Manage OBS Source Filters in Go Source: https://context7.com/xaionaro-go/goobs/llms.txt Demonstrates how to list, create, and toggle the enabled state of audio and video filters on a specific OBS source using the goobs library. ```go package main import ( "fmt" "log" "github.com/andreykaipov/goobs" "github.com/andreykaipov/goobs/api/requests/filters" ) func main() { client, err := goobs.New("localhost:4455", goobs.WithPassword("your-password")) if err != nil { log.Fatal(err) } defer client.Disconnect() sourceName := "Webcam" // List all filters on a source listParams := filters.NewGetSourceFilterListParams().WithSourceName(sourceName) filterList, err := client.Filters.GetSourceFilterList(listParams) if err != nil { log.Fatal(err) } fmt.Printf("Filters on %s:\n", sourceName) for _, filter := range filterList.Filters { fmt.Printf(" - %s (kind: %s, enabled: %v)\n", filter.FilterName, filter.FilterKind, filter.FilterEnabled) } // Add a color correction filter createParams := filters.NewCreateSourceFilterParams(). WithSourceName(sourceName). WithFilterName("My Color Filter"). WithFilterKind("color_filter_v2"). WithFilterSettings(map[string]any{ "brightness": 0.1, "contrast": 0.1, "saturation": 0.2, }) _, err = client.Filters.CreateSourceFilter(createParams) if err != nil { log.Fatal(err) } fmt.Println("Color filter added!") // Enable/disable a filter enableParams := filters.NewSetSourceFilterEnabledParams(). WithSourceName(sourceName). WithFilterName("My Color Filter"). WithFilterEnabled(false) _, err = client.Filters.SetSourceFilterEnabled(enableParams) if err != nil { log.Fatal(err) } fmt.Println("Filter disabled") } ``` -------------------------------- ### General: GetVersion Source: https://context7.com/xaionaro-go/goobs/llms.txt Retrieves the version information of the OBS Studio instance, the obs-websocket server, and the protocol version. ```APIDOC ## GET /General/GetVersion ### Description Returns the OBS Studio version, the obs-websocket server version, and the supported protocol version. ### Method GET ### Endpoint client.General.GetVersion() ### Response #### Success Response (200) - **ObsVersion** (string) - The version of OBS Studio. - **ObsWebSocketVersion** (string) - The version of the obs-websocket server. - **RpcVersion** (string) - The version of the RPC protocol. ### Response Example { "ObsVersion": "30.2.2", "ObsWebSocketVersion": "5.5.2", "RpcVersion": "1" } ``` -------------------------------- ### Execute Vendor-Specific Requests in Go Source: https://context7.com/xaionaro-go/goobs/llms.txt Shows how to interact with third-party OBS plugins that expose custom APIs using the CallVendorRequest method. ```go package main import ( "fmt" "log" "github.com/andreykaipov/goobs" "github.com/andreykaipov/goobs/api/requests/general" ) func main() { client, err := goobs.New("localhost:4455", goobs.WithPassword("your-password")) if err != nil { log.Fatal(err) } defer client.Disconnect() // Call a vendor-specific request (example: obs-shutdown-plugin) params := general.NewCallVendorRequestParams(). WithVendorName("obs-shutdown-plugin"). WithRequestType("shutdown"). WithRequestData(map[string]interface{}{ "reason": "automated cleanup", "support_url": "https://github.com/norihiro/obs-shutdown-plugin/issues", "force": true, }) resp, err := client.General.CallVendorRequest(params) if err != nil { log.Fatal(err) } fmt.Printf("Vendor response: %+v\n", resp) } ``` -------------------------------- ### Filters module request mapping Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Demonstrates how to access source filter-related OBS requests through the client.Filters sub-module. ```go client.Filters.CreateSourceFilter(...) client.Filters.GetSourceFilterList(...) client.Filters.RemoveSourceFilter(...) ``` -------------------------------- ### General API Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md General utility methods for interacting with OBS. ```APIDOC ## General API This section covers general utility functions for interacting with OBS. ### BroadcastCustomEvent **Description**: Broadcasts a custom event to OBS. **Method**: Not specified (assumed to be part of the General client methods) **Endpoint**: N/A ### CallVendorRequest **Description**: Calls a vendor-specific request. **Method**: Not specified (assumed to be part of the General client methods) **Endpoint**: N/A ### GetHotkeyList **Description**: Retrieves a list of all available hotkeys in OBS. **Method**: Not specified (assumed to be part of the General client methods) **Endpoint**: N/A ### GetStats **Description**: Retrieves OBS performance statistics. **Method**: Not specified (assumed to be part of the General client methods) **Endpoint**: N/A ### GetVersion **Description**: Retrieves the OBS version and obs-websocket version. **Method**: Not specified (assumed to be part of the General client methods) **Endpoint**: N/A ### Sleep **Description**: Pauses OBS execution for a specified duration. **Method**: Not specified (assumed to be part of the General client methods) **Endpoint**: N/A ### TriggerHotkeyByKeySequence **Description**: Triggers a hotkey using its key sequence. **Method**: Not specified (assumed to be part of the General client methods) **Endpoint**: N/A ### TriggerHotkeyByName **Description**: Triggers a hotkey by its name. **Method**: Not specified (assumed to be part of the General client methods) **Endpoint**: N/A ``` -------------------------------- ### Config API Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Methods for managing OBS profiles, scene collections, and persistent data. ```APIDOC ## Config API This section details the methods available for configuration management within the goobs client. ### CreateProfile **Description**: Creates a new OBS profile. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### CreateSceneCollection **Description**: Creates a new OBS scene collection. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### GetPersistentData **Description**: Retrieves persistent data associated with OBS. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### GetProfileList **Description**: Retrieves a list of available OBS profiles. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### GetProfileParameter **Description**: Retrieves a specific parameter from the current OBS profile. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### GetRecordDirectory **Description**: Retrieves the current recording directory in OBS. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### GetSceneCollectionList **Description**: Retrieves a list of available OBS scene collections. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### GetStreamServiceSettings **Description**: Retrieves the current stream service settings in OBS. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### GetVideoSettings **Description**: Retrieves the current video settings in OBS. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### RemoveProfile **Description**: Removes an OBS profile. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### SetCurrentProfile **Description**: Sets the current active OBS profile. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### SetCurrentSceneCollection **Description**: Sets the current active OBS scene collection. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### SetPersistentData **Description**: Sets persistent data in OBS. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### SetProfileParameter **Description**: Sets a specific parameter in the current OBS profile. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### SetRecordDirectory **Description**: Sets the recording directory in OBS. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### SetStreamServiceSettings **Description**: Sets the stream service settings in OBS. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ### SetVideoSettings **Description**: Sets the video settings in OBS. **Method**: Not specified (assumed to be part of the Config client methods) **Endpoint**: N/A ``` -------------------------------- ### Connect to OBS WebSocket Server in Go Source: https://github.com/xaionaro-go/goobs/blob/main/docs/README.md Establishes a connection to the OBS WebSocket server using the goobs client. It requires the server address and an optional password for authentication. ```go client, err := goobs.New("localhost:4455", goobs.WithPassword("bigmoney420!!")) ``` -------------------------------- ### Control Recording with goobs Source: https://context7.com/xaionaro-go/goobs/llms.txt Demonstrates how to check the current recording status, start/stop recording, and retrieve metadata like duration and file output path. ```go package main import ( "fmt" "log" "time" "github.com/andreykaipov/goobs" ) func main() { client, err := goobs.New("localhost:4455", goobs.WithPassword("your-password")) if err != nil { log.Fatal(err) } defer client.Disconnect() // Check current recording status status, err := client.Record.GetRecordStatus() if err != nil { log.Fatal(err) } fmt.Printf("Recording active: %v\n", status.OutputActive) fmt.Printf("Recording paused: %v\n", status.OutputPaused) // Start recording _, err = client.Record.StartRecord() if err != nil { log.Fatal(err) } fmt.Println("Recording started!") // Record for 5 seconds time.Sleep(5 * time.Second) // Check recording duration status, _ = client.Record.GetRecordStatus() fmt.Printf("Recording duration: %s\n", status.OutputTimecode) fmt.Printf("Bytes recorded: %.0f\n", status.OutputBytes) // Stop recording stopResp, err := client.Record.StopRecord() if err != nil { log.Fatal(err) } fmt.Printf("Recording saved to: %s\n", stopResp.OutputPath) } ``` -------------------------------- ### Scenes: CreateScene Source: https://context7.com/xaionaro-go/goobs/llms.txt Creates a new scene in OBS Studio with the specified name. ```APIDOC ## POST /Scenes/CreateScene ### Description Creates a new scene with the provided name. ### Method POST ### Endpoint client.Scenes.CreateScene(params) ### Request Body - **sceneName** (string) - Required - The name for the new scene. ### Request Example { "sceneName": "My New Scene" } ### Response #### Success Response (200) - **SceneUuid** (string) - The UUID of the newly created scene. ### Response Example { "SceneUuid": "new-uuid-123" } ``` -------------------------------- ### Inputs API Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Methods for managing inputs (sources like microphones, cameras, etc.) in OBS. ```APIDOC ## Inputs API This section details the methods for managing inputs (sources) in OBS. ### CreateInput **Description**: Creates a new input (source). **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetInputAudioBalance **Description**: Retrieves the audio balance of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetInputAudioMonitorType **Description**: Retrieves the audio monitor type of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetInputAudioSyncOffset **Description**: Retrieves the audio sync offset of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetInputAudioTracks **Description**: Retrieves the audio tracks configuration of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetInputDefaultSettings **Description**: Retrieves the default settings for a specific input kind. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetInputKindList **Description**: Retrieves a list of available input kinds in OBS. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetInputList **Description**: Retrieves a list of all inputs (sources) in OBS. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetInputMute **Description**: Retrieves the mute status of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetInputPropertiesListPropertyItems **Description**: Retrieves items for a list-type property of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetInputSettings **Description**: Retrieves the settings of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetInputVolume **Description**: Retrieves the volume level of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### GetSpecialInputs **Description**: Retrieves a list of special inputs (e.g., Desktop Audio). **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### PressInputPropertiesButton **Description**: Simulates a button press on an input's properties. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### RemoveInput **Description**: Removes an input (source). **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### SetInputAudioBalance **Description**: Sets the audio balance of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### SetInputAudioMonitorType **Description**: Sets the audio monitor type of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### SetInputAudioSyncOffset **Description**: Sets the audio sync offset of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### SetInputAudioTracks **Description**: Sets the audio tracks configuration of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### SetInputMute **Description**: Sets the mute status of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### SetInputName **Description**: Renames an input (source). **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### SetInputSettings **Description**: Updates the settings of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### SetInputVolume **Description**: Sets the volume level of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ### ToggleInputMute **Description**: Toggles the mute status of an input. **Method**: Not specified (assumed to be part of the Inputs client methods) **Endpoint**: N/A ``` -------------------------------- ### Subscribe to OBS Real-time Events Source: https://context7.com/xaionaro-go/goobs/llms.txt Shows how to subscribe to OBS events using the Listen method. It utilizes type assertions to handle specific events like scene changes, volume updates, and recording state changes. ```go package main import ( "fmt" "os" "github.com/andreykaipov/goobs" "github.com/andreykaipov/goobs/api/events" "github.com/andreykaipov/goobs/api/events/subscriptions" ) func main() { // Subscribe to all events including high-volume InputVolumeMeters client, err := goobs.New( "localhost:4455", goobs.WithPassword("your-password"), goobs.WithEventSubscriptions(subscriptions.All|subscriptions.InputVolumeMeters), ) if err != nil { panic(err) } defer client.Disconnect() // Listen for events in the background go client.Listen(func(event any) { switch e := event.(type) { case *events.CurrentProgramSceneChanged: fmt.Printf("Scene changed to: %s\n", e.SceneName) case *events.SceneItemEnableStateChanged: fmt.Printf("Item %d visibility: %v\n", e.SceneItemId, e.SceneItemEnabled) case *events.InputVolumeChanged: fmt.Printf("%s volume: %.2f dB\n", e.InputName, e.InputVolumeDb) case *events.RecordStateChanged: fmt.Printf("Record state: %s\n", e.OutputState) case *events.StreamStateChanged: fmt.Printf("Stream state: %s\n", e.OutputState) case *events.ExitStarted: fmt.Println("OBS is closing!") os.Exit(0) default: fmt.Printf("Event: %T\n", e) } }) // Keep the program running select {} } ``` -------------------------------- ### Scene Management Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Methods for manipulating scenes, including creation, removal, and switching between program and preview scenes. ```APIDOC ## POST /scenes/set-current-program ### Description Sets the current active program scene. ### Method POST ### Endpoint `client.Scenes.SetCurrentProgramScene(...)` ### Request Example { "sceneName": "string" } ### Response #### Success Response (200) - **status** (string) - Confirmation of scene switch. ``` -------------------------------- ### Scenes: GetSceneList Source: https://context7.com/xaionaro-go/goobs/llms.txt Retrieves a list of all scenes currently configured in the OBS Studio instance. ```APIDOC ## GET /Scenes/GetSceneList ### Description Fetches the current program scene and a list of all available scenes with their respective UUIDs. ### Method GET ### Endpoint client.Scenes.GetSceneList() ### Response #### Success Response (200) - **CurrentProgramSceneName** (string) - The name of the currently active scene. - **Scenes** (array) - List of scene objects containing SceneName and SceneUuid. ### Response Example { "CurrentProgramSceneName": "Scene 1", "Scenes": [ { "SceneName": "Scene 1", "SceneUuid": "uuid-1" }, { "SceneName": "Scene 2", "SceneUuid": "uuid-2" } ] } ``` -------------------------------- ### Configure Advanced Client Options in Go Source: https://context7.com/xaionaro-go/goobs/llms.txt Demonstrates how to customize the goobs client with TLS, custom headers, timeouts, and event subscriptions for secure or complex network environments. ```go package main import ( "crypto/tls" "log" "net/http" "time" "github.com/andreykaipov/goobs" "github.com/andreykaipov/goobs/api/events/subscriptions" "github.com/gorilla/websocket" ) func main() { // Custom dialer with TLS configuration (for wss:// connections behind reverse proxy) dialer := &websocket.Dialer{ HandshakeTimeout: 10 * time.Second, TLSClientConfig: &tls.Config{ InsecureSkipVerify: false, }, } // Custom headers for authentication or identification headers := http.Header{ "User-Agent": []string{"my-obs-automation/1.0"}, } client, err := goobs.New( "obs.example.com:4455", goobs.WithPassword("secure-password"), goobs.WithScheme("wss"), // Use secure WebSocket goobs.WithDialer(dialer), // Custom dialer goobs.WithRequestHeader(headers), // Custom headers goobs.WithResponseTimeout(30*time.Second), // 30 second timeout goobs.WithEventSubscriptions(subscriptions.All), // Subscribe to all events ) if err != nil { log.Fatal(err) } defer client.Disconnect() log.Println("Connected with custom configuration!") } ``` -------------------------------- ### Capture OBS Source Screenshots Source: https://context7.com/xaionaro-go/goobs/llms.txt Demonstrates how to request a base64-encoded screenshot of a specific source from OBS. The code includes decoding the base64 string and saving it as a PNG file. ```go package main import ( "encoding/base64" "image/png" "log" "os" "strings" "github.com/andreykaipov/goobs" "github.com/andreykaipov/goobs/api/requests/sources" ) func main() { client, err := goobs.New("localhost:4455", goobs.WithPassword("your-password")) if err != nil { log.Fatal(err) } defer client.Disconnect() // Take a screenshot of a source (webcam, scene, etc.) params := sources.NewGetSourceScreenshotParams(). WithSourceName("Webcam"). WithImageFormat("png"). WithImageCompressionQuality(-1). // Default quality WithImageWidth(1920). WithImageHeight(1080) screenshot, err := client.Sources.GetSourceScreenshot(params) if err != nil { log.Fatal(err) } // Decode the base64 image data (remove data URI prefix) data := screenshot.ImageData[strings.IndexByte(screenshot.ImageData, ',')+1:] reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(data)) image, err := png.Decode(reader) if err != nil { log.Fatal(err) } // Save to file f, err := os.Create("screenshot.png") if err != nil { log.Fatal(err) } defer f.Close() err = png.Encode(f, image) if err != nil { log.Fatal(err) } log.Println("Screenshot saved to screenshot.png") } ``` -------------------------------- ### Run goobs Docker with Custom Build and VNC Source: https://github.com/xaionaro-go/goobs/blob/main/docker/README.md This command runs a goobs Docker container built from a local Dockerfile, enabling VNC and exposing both OBS-WebSocket and VNC ports. It's useful for testing changes to the Docker image or OBS configurations. ```console ❯ docker run --rm -it --name obs -p 4455:1234 -e vnc=1 -p 5900:5900 "$(docker build -q docker)" ``` -------------------------------- ### Manage Scene Items with goobs Source: https://context7.com/xaionaro-go/goobs/llms.txt Demonstrates how to list items within an OBS scene, toggle their visibility, and reorder them. Requires an active connection to the OBS WebSocket server. ```go package main import ( "fmt" "log" "github.com/andreykaipov/goobs" "github.com/andreykaipov/goobs/api/requests/sceneitems" ) func main() { client, err := goobs.New("localhost:4455", goobs.WithPassword("your-password")) if err != nil { log.Fatal(err) } defer client.Disconnect() sceneName := "Scene" // Get all scene items in a scene params := sceneitems.NewGetSceneItemListParams().WithSceneName(sceneName) items, err := client.SceneItems.GetSceneItemList(params) if err != nil { log.Fatal(err) } fmt.Println("Scene items:") for _, item := range items.SceneItems { fmt.Printf(" index=%d, id=%d, type=%s, name=%s\n", item.SceneItemIndex, item.SceneItemID, item.SourceType, item.SourceName) } // Toggle visibility of a scene item (hide it) if len(items.SceneItems) > 0 { item := items.SceneItems[0] enableParams := sceneitems.NewSetSceneItemEnabledParams(). WithSceneName(sceneName). WithSceneItemId(item.SceneItemID). WithSceneItemEnabled(false) _, err = client.SceneItems.SetSceneItemEnabled(enableParams) if err != nil { log.Fatal(err) } fmt.Printf("Hidden item: %s\n", item.SourceName) } // Reorder scene items (move first item to end) if len(items.SceneItems) > 1 { firstItem := items.SceneItems[0] indexParams := sceneitems.NewSetSceneItemIndexParams(). WithSceneName(sceneName). WithSceneItemId(firstItem.SceneItemID). WithSceneItemIndex(len(items.SceneItems) - 1) _, err = client.SceneItems.SetSceneItemIndex(indexParams) if err != nil { log.Fatal(err) } fmt.Printf("Moved '%s' to end of list\n", firstItem.SourceName) } } ``` -------------------------------- ### Outputs Management Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Methods for controlling OBS outputs, including replay buffers, virtual cameras, and general output status. ```APIDOC ## POST /outputs/start ### Description Starts a specific OBS output. ### Method POST ### Endpoint `client.Outputs.StartOutput(...)` ### Request Example { "outputName": "string" } ### Response #### Success Response (200) - **status** (string) - The status of the output operation. ``` -------------------------------- ### Media Inputs API Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Methods for controlling media inputs (e.g., video files, streams) in OBS. ```APIDOC ## Media Inputs API This section covers methods for controlling media inputs in OBS. ### GetMediaInputStatus **Description**: Retrieves the status of a media input. **Method**: Not specified (assumed to be part of the MediaInputs client methods) **Endpoint**: N/A ### OffsetMediaInputCursor **Description**: Offsets the cursor position of a media input. **Method**: Not specified (assumed to be part of the MediaInputs client methods) **Endpoint**: N/A ### SetMediaInputCursor **Description**: Sets the cursor position of a media input. **Method**: Not specified (assumed to be part of the MediaInputs client methods) **Endpoint**: N/A ### TriggerMediaInputAction **Description**: Triggers an action on a media input (e.g., play, pause). **Method**: Not specified (assumed to be part of the MediaInputs client methods) **Endpoint**: N/A ``` -------------------------------- ### Recording Controls Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Methods for managing OBS recording sessions, including pausing, resuming, and splitting files. ```APIDOC ## POST /record/start ### Description Starts the OBS recording process. ### Method POST ### Endpoint `client.Record.StartRecord(...)` ### Response #### Success Response (200) - **status** (string) - Confirmation of recording start. ``` -------------------------------- ### Filters API Source: https://github.com/xaionaro-go/goobs/blob/main/docs/request-mapping.md Methods for managing filters applied to sources in OBS. ```APIDOC ## Filters API This section details the methods available for managing filters in OBS. ### CreateSourceFilter **Description**: Creates a new filter for a given source. **Method**: Not specified (assumed to be part of the Filters client methods) **Endpoint**: N/A ### GetSourceFilter **Description**: Retrieves information about a specific filter on a source. **Method**: Not specified (assumed to be part of the Filters client methods) **Endpoint**: N/A ### GetSourceFilterDefaultSettings **Description**: Retrieves the default settings for a specific filter kind. **Method**: Not specified (assumed to be part of the Filters client methods) **Endpoint**: N/A ### GetSourceFilterKindList **Description**: Retrieves a list of available filter kinds in OBS. **Method**: Not specified (assumed to be part of the Filters client methods) **Endpoint**: N/A ### GetSourceFilterList **Description**: Retrieves a list of all filters applied to a source. **Method**: Not specified (assumed to be part of the Filters client methods) **Endpoint**: N/A ### RemoveSourceFilter **Description**: Removes a filter from a source. **Method**: Not specified (assumed to be part of the Filters client methods) **Endpoint**: N/A ### SetSourceFilterEnabled **Description**: Enables or disables a filter on a source. **Method**: Not specified (assumed to be part of the Filters client methods) **Endpoint**: N/A ### SetSourceFilterIndex **Description**: Sets the order (index) of a filter on a source. **Method**: Not specified (assumed to be part of the Filters client methods) **Endpoint**: N/A ### SetSourceFilterName **Description**: Renames a filter on a source. **Method**: Not specified (assumed to be part of the Filters client methods) **Endpoint**: N/A ### SetSourceFilterSettings **Description**: Updates the settings of a filter on a source. **Method**: Not specified (assumed to be part of the Filters client methods) **Endpoint**: N/A ``` -------------------------------- ### Access Raw OBS API Response (Go) Source: https://github.com/xaionaro-go/goobs/blob/main/docs/README.md Provides a method to access the raw JSON response from an OBS API call when the generated Go struct might be missing fields. It uses `json.Unmarshal` to parse the raw data. ```go resp, _ := client.Inputs.GetInputList() data := map[string]any{} if err := json.Unmarshal(resp.GetRaw(), &data); err != nil { panic(err) } fmt.Println(data["inputs"]) ``` -------------------------------- ### Enable VNC with Password in goobs Docker Container Source: https://github.com/xaionaro-go/goobs/blob/main/docker/README.md This command runs the goobs Docker container with VNC enabled and sets a password for VNC access. This enhances security when connecting to the OBS instance remotely via VNC. ```console ❯ docker run --rm -it -e vnc=1 -e vnc_password=delicious -p 5900:5900 ghcr.io/andreykaipov/goobs ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.