Stages.SseClient 1.0.1

dotnet add package Stages.SseClient --version 1.0.1
                    
NuGet\Install-Package Stages.SseClient -Version 1.0.1
                    
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="Stages.SseClient" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Stages.SseClient" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Stages.SseClient" />
                    
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 Stages.SseClient --version 1.0.1
                    
#r "nuget: Stages.SseClient, 1.0.1"
                    
#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 Stages.SseClient@1.0.1
                    
#: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=Stages.SseClient&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Stages.SseClient&version=1.0.1
                    
Install as a Cake Tool

Stages SSE Client

A .NET SDK for subscribing to Server-Sent Events (SSE) from Stages Studio.

Features

  • Real-time event streaming from Stages Studio rooms
  • API key authentication with automatic room configuration
  • Support for training session interval change events
  • Multi-target support for .NET 8, 9, and 10

Installation

dotnet add package Stages.SseClient

Quick Start

using Stages.SseClient;
using Stages.SseClient.Authentication.RoomConfiguration;

// Step 1: Authenticate with your API key to get room configuration
using var authenticator = new RoomAuthenticator();
var config = await authenticator.AuthenticateAsync("https://your-stages-service.com", "your-api-key"); // TODO: Update this with the correct URL before publishing anywhere. 

// Step 2: Connect to the SSE stream and handle events
using var client = new SseClient(config.SseUrl)
    .OnTrainingSessionIntervalChanged(evt =>
    {
        var current = evt.Payload.Data.CurrentInterval;

        var target = current?.Interval?.Primary?.Value;

        Console.WriteLine($"Target: {target}% FTP");
    })
    .OnError(ex => Console.WriteLine($"Error: {ex.Message}"));

await client.ConnectAsync();

Authentication

The SDK uses a two-step authentication process:

  1. Room Authentication: Exchange your API key for room configuration
  2. SSE Connection: Connect to the SSE endpoint provided in the configuration
using var authenticator = new RoomAuthenticator();

try
{
    RoomConfiguration config = await authenticator.AuthenticateAsync(serviceUrl, apiKey);

    using var client = new SseClient(config.SseUrl);
    client.OnTrainingSessionIntervalChanged(evt =>
        {
            // Handle interval change events
        });
}
catch (AuthenticationException ex)
{
    // Handle authentication failures
}
catch (Exception ex)
{
    // Handle other errors
}

Configuration Format

The configuration is returned in the following JSON format:

{
    "clientId": "123456",
    "roomId": "123",
    "sseUrl": "https://next-sse.stagescloud.com/rooms/123"
}

Event Handling

Training Session Interval Changed

Triggered when the current interval changes during a training session:

client.OnTrainingSessionIntervalChanged(evt =>
{
    // Event metadata
    Console.WriteLine($"Session ID: {evt.SessionId}");
    Console.WriteLine($"Room ID: {evt.RoomId}");

    // Current interval
    var current = evt.Payload.Data.CurrentInterval;
    if (current?.Interval != null)
    {
        Console.WriteLine($"Title: {current.Interval.Title}");
        Console.WriteLine($"Duration: {current.Interval.DurationValue}s");
        Console.WriteLine($"Target: {current.Interval.Primary?.Value}% FTP");
        Console.WriteLine($"State: {current.State}");
    }

    // Next interval (if available)
    var next = evt.Payload.Data.NextInterval;
    if (next?.Interval != null)
    {
        Console.WriteLine($"Up next: {next.Interval.Title}");
    }
});

Power Zone Conversions

The SDK includes the PowerZoneHelper class, which returns the resulting zone, based on the FTP percentage in the interval target. It can also return the target colour for the interval.

client.OnTrainingSessionIntervalChanged(evt =>
{
    var current = evt.Payload.Data.CurrentInterval;
    if (current?.Interval != null)
    {
        Console.WriteLine($"Target: {current.Interval.Primary?.Value}% FTP");
        Console.WriteLine($"Target Zone Name: {PowerZoneHelper.GetZone(current?.Interval?.Primary?.Value)}");
        Console.WriteLine($"Color: {PowerZoneHelper.GetColor(current?.Interval?.Primary?.Value)}");
    }
});

Error Handling

Register an error handler to catch connection and parsing errors:

client.OnError(ex =>
{
    Console.WriteLine($"Error: {ex.GetType().Name} - {ex.Message}");
});

Connection Management

Connecting with Cancellation

using var cts = new CancellationTokenSource();

// Cancel on Ctrl+C
Console.CancelKeyPress += (_, e) =>
{
    e.Cancel = true;
    cts.Cancel();
};

try
{
    await client.ConnectAsync(cts.Token);
}
catch (OperationCanceledException)
{
    // Normal cancellation
}

Disconnection

client.Disconnect();

Test Application

The repository includes a test application that demonstrates all SDK features:

cd Stages.SseClient.TestApp

# Using command line arguments
dotnet run -- --api-key <your-api-key> --service-url <service-url>
dotnet run -- -k <your-api-key> -s <service-url>

# Using environment variables
export STAGES_API_KEY=your-api-key
export STAGES_SERVICE_URL=https://your-stages-service.com
dotnet run

Requirements

  • .NET 8.0, 9.0, or 10.0

License

Proprietary - SPIA Cycling

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

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
1.0.1 136 1/30/2026