MDH.Streamdeck.Companion
1.0.2
dotnet add package MDH.Streamdeck.Companion --version 1.0.2
NuGet\Install-Package MDH.Streamdeck.Companion -Version 1.0.2
<PackageReference Include="MDH.Streamdeck.Companion" Version="1.0.2" />
<PackageVersion Include="MDH.Streamdeck.Companion" Version="1.0.2" />
<PackageReference Include="MDH.Streamdeck.Companion" />
paket add MDH.Streamdeck.Companion --version 1.0.2
#r "nuget: MDH.Streamdeck.Companion, 1.0.2"
#:package MDH.Streamdeck.Companion@1.0.2
#addin nuget:?package=MDH.Streamdeck.Companion&version=1.0.2
#tool nuget:?package=MDH.Streamdeck.Companion&version=1.0.2
MDH.Streamdeck.Companion
Embeddable HTTP + SSE control API for a host application. Register named actions and a state provider; drive them from a Stream Deck (via Bitfocus Companion) or any HTTP client.
Targets netstandard2.0, net48, net8.0-windows. The WPF status bar item and
settings editor are on the two Windows targets only.
Install
dotnet add package MDH.Streamdeck.Companion
Quick start
var settings = CompanionSettings.LoadFromFile(@"C:\ProgramData\YourApp\companion.xml");
var server = new CompanionServer(settings)
.SetStateProvider(() => JsonSerializer.Serialize(new { heat = _app.Heat?.Name }))
.MapAction("start", _ => _app.StartTimer())
.MapAction("stop", _ => _app.StopTimer())
.MapAction("stand", q => _app.SelectStand(CompanionQuery.GetInt(q, "n", 1)));
server.OnLog += Log;
server.OnError += Log;
server.Start();
Endpoints
With default settings:
| Route | Purpose |
|---|---|
/api/{action} |
Invokes a registered action. |
/api/state |
Current state JSON, once. |
/api/events |
Server-Sent Events; pushes state on a cadence. |
Routing is path-only; any HTTP method works.
API
CompanionServer MapAction(string relativePath, Action<IReadOnlyDictionary<string, string>> handler);
CompanionServer MapAction(string relativePath, Func<IReadOnlyDictionary<string, string>, string?> handler);
CompanionServer SetStateProvider(Func<string> stateJsonProvider);
void Start();
void Stop();
bool IsRunning { get; }
int ConnectedClients { get; }
event Action<string>? OnLog;
event Action<string>? OnError;
event Action<int>? ClientCountChanged;
Start() is a no-op when Enabled is false or already running. The Func
overload returns a JSON response body; null replies {"ok":true}.
ConnectedClients counts open events streams. ClientCountChanged fires on
connect and disconnect.
Query parameters
CompanionQuery.Get(q, "name"); // string or null
CompanionQuery.GetInt(q, "n", 1); // fallback when absent or unparseable
CompanionQuery.GetBool(q, "on", true); // "false"/"0" are false; anything else true
Settings
| Field | Default | Description |
|---|---|---|
Enabled |
false |
When off, Start() is a no-op. |
Host |
0.0.0.0 |
Interface to bind. 0.0.0.0 = all. |
Port |
10000 |
TCP port. |
BasePath |
/api |
Route prefix. Must start with a slash. |
PushIntervalMs |
100 |
events push cadence. |
IsConfigured / ConfigurationProblem report whether the settings are usable.
LoadFromFile returns defaults if the file is missing; throws if it exists and
cannot be parsed.
Changing settings on a running server has no effect until Stop() then Start().
Embed in a host's settings tree:
[Category("Stream Deck"), DisplayName("Connection")]
public CompanionSettings StreamDeck { get; set; } = new CompanionSettings();
Serialises as one XML element (MdhStreamdeckCompanionSettings) and expands in a
PropertyGrid.
WPF status bar item
<StatusBar>
<companion:CompanionStatusBarItem x:Name="Item" FontWeight="Bold" />
</StatusBar>
Item.Settings = mySettings;
Item.StartRequested += (s, e) => server.Start();
Item.StopRequested += (s, e) => server.Stop();
server.ClientCountChanged += n => Dispatcher.Invoke(() => Item.ClientCount = n);
Displays MDH Stream Deck (1) — the label plus the connected client count.
Appearance: Label, FontWeight, FontSize, FontFamily, Padding, and one
brush property per state (RunningBackground, StoppedForeground, …).
Add host-specific menu items to the right-click menu, in XAML or in code. They render between Start/Stop and Properties.
<companion:CompanionStatusBarItem>
<companion:CompanionStatusBarItem.HostMenuItems>
<MenuItem Header="Open dashboard" Click="OnClick" />
</companion:CompanionStatusBarItem.HostMenuItems>
</companion:CompanionStatusBarItem>
Item.HostMenuItems.Add(new MenuItem { Header = "Open dashboard" });
Threading
Actions, the state provider, OnLog, OnError and ClientCountChanged all run
on Kestrel request threads. Marshal to the UI thread in your handlers:
.MapAction("start", _ => Dispatcher.Invoke(() => _app.StartTimer()))
Status
Not verified against a Stream Deck since the library moved repositories.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net8.0-windows7.0 is compatible. net9.0 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.8
- Microsoft.AspNetCore.Hosting (>= 2.3.11)
- Microsoft.AspNetCore.Server.Kestrel (>= 2.3.11)
-
.NETStandard 2.0
- Microsoft.AspNetCore.Hosting (>= 2.3.11)
- Microsoft.AspNetCore.Server.Kestrel (>= 2.3.11)
-
net8.0-windows7.0
- Microsoft.AspNetCore.Hosting (>= 2.3.11)
- Microsoft.AspNetCore.Server.Kestrel (>= 2.3.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.