ObsWebSocket.Core 0.2.0-beta1

This is a prerelease version of ObsWebSocket.Core.
dotnet add package ObsWebSocket.Core --version 0.2.0-beta1
                    
NuGet\Install-Package ObsWebSocket.Core -Version 0.2.0-beta1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ObsWebSocket.Core" Version="0.2.0-beta1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ObsWebSocket.Core" Version="0.2.0-beta1" />
                    
Directory.Packages.props
<PackageReference Include="ObsWebSocket.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ObsWebSocket.Core --version 0.2.0-beta1
                    
#r "nuget: ObsWebSocket.Core, 0.2.0-beta1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ObsWebSocket.Core@0.2.0-beta1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ObsWebSocket.Core&version=0.2.0-beta1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=ObsWebSocket.Core&version=0.2.0-beta1&prerelease
                    
Install as a Cake Tool

ObsWebSocket.Core

Modern .NET client for OBS Studio WebSocket v5, with generated protocol types and DI-first integration.

Build Status NuGet Version License: MIT

Targets

  • net10.0
  • net9.0

Install

dotnet add package ObsWebSocket.Core

What You Get

  • Strongly typed request/response DTOs generated from OBS protocol
  • Strongly typed OBS event args
  • Async-first API (Task, ValueTask, cancellation support)
  • DI helpers via AddObsWebSocketClient()
  • Configurable JSON or MessagePack transport
  • Reconnect and timeout options via ObsWebSocketClientOptions
  • Convenience helpers for common scene/input/filter workflows

Important Caveats

  • This library is for OBS WebSocket v5 only (OBS Studio 28+).
  • Make sure OBS WebSocket server is enabled (Tools -> WebSocket Server Settings).
  • If you use authentication, provide the correct password in options/config.

Quick Start (DI)

appsettings.json:

{
  "Obs": {
    "ServerUri": "ws://localhost:4455",
    "Password": "",
    "EventSubscriptions": null,
    "Format": "Json"
  }
}

Program.cs:

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ObsWebSocket.Core;

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);

builder.Services.Configure<ObsWebSocketClientOptions>(
    builder.Configuration.GetSection("Obs"));

builder.Services.AddObsWebSocketClient();
builder.Services.AddHostedService<Worker>();

await builder.Build().RunAsync();

Worker example:

using Microsoft.Extensions.Hosting;
using ObsWebSocket.Core;
using ObsWebSocket.Core.Events.Generated;

public sealed class Worker(ObsWebSocketClient client) : IHostedService
{
    public async Task StartAsync(CancellationToken ct)
    {
        client.CurrentProgramSceneChanged += OnSceneChanged;
        await client.ConnectAsync(ct);

        var version = await client.GetVersionAsync(cancellationToken: ct);
        Console.WriteLine($"Connected to OBS {version?.ObsVersion}");
    }

    public async Task StopAsync(CancellationToken ct)
    {
        client.CurrentProgramSceneChanged -= OnSceneChanged;
        if (client.IsConnected)
        {
            await client.DisconnectAsync();
        }
    }

    private static void OnSceneChanged(object? sender, CurrentProgramSceneChangedEventArgs e)
    {
        Console.WriteLine($"Program scene: {e.EventData.SceneName}");
    }
}

Helpers and Advanced Usage

Common helper APIs include:

  • SwitchSceneAndWaitAsync(...)
  • SetInputTextAsync(...)
  • SetSceneItemEnabledAsync(...)
  • SourceExistsAsync(...)
  • GetSourceFilterSettingsAsync<T>(...)
  • WaitForEventAsync<TEventArgs>(...)

For generated request models and direct requests, see:

  • ObsWebSocket.Core.Protocol.Requests
  • ObsWebSocket.Core.Protocol.Responses
  • ObsWebSocket.Core.Events.Generated

Batch API note (AOT-safe path):

  • BatchRequestItem.RequestData should be null, JsonElement, or a generated *RequestData DTO from ObsWebSocket.Core.Protocol.Requests.
  • Arbitrary anonymous/POCO objects are not guaranteed to be serializable in Native AOT builds.

Example App

ObsWebSocket.Example contains a host-based sample using configuration + DI.

  • Interactive mode: starts a command loop (help, version, scene, batch-example, etc.)
  • Transport validation mode: runs JSON + MsgPack validation cycles (scene/input/filter stub-heavy calls), then enters the interactive loop
  • One-shot mode: pass a command as process arguments to run it directly and exit (for CI/automation), for example:
    • ObsWebSocket.Example run-transport-tests

appsettings.json:

{
  "Obs": {
    "ServerUri": "ws://localhost:4455",
    "Password": "",
    "EventSubscriptions": null,
    "Format": "Json"
  },
  "ExampleValidation": {
    "RunValidationOnStartup": false,
    "ValidationIterations": 1
  }
}

Interactive command to run validation on demand:

  • run-transport-tests

Native AOT Example

Build and run the example as Native AOT:

dotnet publish ObsWebSocket.Example/ObsWebSocket.Example.csproj -c Release -r win-x64 --self-contained true
./ObsWebSocket.Example/bin/Release/net10.0/win-x64/publish/ObsWebSocket.Example.exe

Contributing

Contributions are welcome. See CONTRIBUTING.md.

License

MIT. See LICENSE.txt.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0-beta1 73 2/24/2026
0.1.5 489 5/8/2025
0.1.4 207 5/6/2025
0.1.3 208 4/30/2025
0.0.0-alpha.0.26 165 4/30/2025