This project contains example applications demonstrating how to use the Obs.NET library to interact with OBS Studio via WebSocket.
See the main README.md for prerequisites and setup instructions.
# Run the default example (connection)
dotnet run --project src/Obs.NET.Example
# Run a specific example
dotnet run --project src/Obs.NET.Example -- --example simple
# List all available examples
dotnet run --project src/Obs.NET.Example -- --list-examples
# Show help
dotnet run --project src/Obs.NET.Example -- --help| Option | Description |
|---|---|
-h, --host <host> |
OBS WebSocket host (default: localhost) |
-p, --port <port> |
OBS WebSocket port (default: 4455) |
--password <password> |
OBS WebSocket password (if authentication is enabled) |
-e, --example <name> |
Example to run (default: connection) |
--list-examples |
List all available examples |
-v, --verbose |
Enable verbose output |
--help |
Show help message |
A minimal, beginner-friendly example using only Console.WriteLine for output. Demonstrates the core workflow without external dependencies.
What it does:
- Connects to OBS
- Creates a new scene called "ObsExample"
- Adds a text source displaying "Hello from Obs.NET!"
- Records a 2-second clip
- Cleans up by deleting the scene
Run it:
dotnet run --project src/Obs.NET.Example -- --example simpleA comprehensive example using Spectre.Console for rich terminal output. Demonstrates connection handling, event subscriptions, and various OBS operations.
What it does:
- Connects to OBS with detailed status output
- Retrieves OBS version information
- Configures a temporary recording directory
- Starts recording
- Creates a text source with timestamp
- Records for 10 seconds
- Displays recording statistics
- Stops recording and shows file details
- Restores original settings
- Displays a summary of received events
Run it:
dotnet run --project src/Obs.NET.Example -- --example connectionTo add a new example:
- Create a new class in the
Examples/directory implementingIExample:
public class MyExample : IExample
{
public string Name => "my-example";
public string Description => "Brief description of what this example does";
public async Task<int> RunAsync(ExampleOptions options, CancellationToken cancellationToken)
{
// Create and configure the client
var clientOptions = new ObsWsClientOptions
{
Host = options.Host,
Port = options.Port,
Password = options.Password,
EventSubscriptions = EventSubscription.General
};
await using var client = new ObsWsClient(clientOptions);
await client.ConnectAsync(cancellationToken);
// Your example code here...
return 0; // Exit code
}
}- Register it in
Program.cs:
Dictionary<string, IExample> examples = new(StringComparer.OrdinalIgnoreCase)
{
["connection"] = new ConnectionAndSetupDemo(),
["simple"] = new SimpleRecordingDemo(),
["my-example"] = new MyExample() // Add your example here
};- Update this file to document your new example.