< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.SignalR.RealtimeBroadcaster
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/SignalR/RealtimeBroadcaster.cs
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 42
Coverable lines: 42
Total lines: 81
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/15/2025 - 21:27:26 Line coverage: 0% (0/42) Total lines: 81 Tag: Kestrun/Kestrun@c33ec02a85e4f8d6061aeaab5a5e8c3a8b665594

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
BroadcastLogAsync()100%210%
BroadcastEventAsync()100%210%
BroadcastToGroupAsync()100%210%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/SignalR/RealtimeBroadcaster.cs

#LineLine coverage
 1using Microsoft.AspNetCore.SignalR;
 2using Kestrun.Utilities.Json;
 3
 4namespace Kestrun.SignalR;
 5
 6/// <summary>
 7/// Default implementation of <see cref="IRealtimeBroadcaster"/> that broadcasts messages via SignalR.
 8/// </summary>
 9/// <remarks>
 10/// Initializes a new instance of the <see cref="RealtimeBroadcaster"/> class.
 11/// </remarks>
 12/// <param name="hubContext">The SignalR hub context for KestrunHub.</param>
 13/// <param name="logger">The Serilog logger instance.</param>
 014public class RealtimeBroadcaster(IHubContext<KestrunHub> hubContext, Serilog.ILogger logger) : IRealtimeBroadcaster
 15{
 016    private readonly IHubContext<KestrunHub> _hubContext = hubContext;
 017    private readonly Serilog.ILogger _logger = logger;
 18
 19    /// <inheritdoc/>
 20    public async Task BroadcastLogAsync(string level, string message, CancellationToken cancellationToken = default)
 21    {
 22        try
 23        {
 024            await _hubContext.Clients.All.SendAsync(
 025                "ReceiveLog",
 026                new
 027                {
 028                    level,
 029                    message,
 030                    timestamp = DateTime.UtcNow
 031                },
 032                cancellationToken);
 33
 034            _logger.Debug("Broadcasted log message: {Level} - {Message}", level, message);
 035        }
 036        catch (Exception ex)
 37        {
 038            _logger.Error(ex, "Failed to broadcast log message: {Level} - {Message}", level, message);
 039        }
 040    }
 41
 42    /// <inheritdoc/>
 43    public async Task BroadcastEventAsync(string eventName, object? data, CancellationToken cancellationToken = default)
 44    {
 45        try
 46        {
 47            // Sanitize data to avoid object cycles (PSObject graphs, etc.)
 048            var safe = PayloadSanitizer.Sanitize(data);
 049            await _hubContext.Clients.All.SendAsync(
 050                "ReceiveEvent",
 051                new
 052                {
 053                    eventName,
 054                    data = safe,
 055                    timestamp = DateTime.UtcNow
 056                },
 057                cancellationToken);
 58
 059            _logger.Debug("Broadcasted event: {EventName}", eventName);
 060        }
 061        catch (Exception ex)
 62        {
 063            _logger.Error(ex, "Failed to broadcast event: {EventName}", eventName);
 064        }
 065    }
 66
 67    /// <inheritdoc/>
 68    public async Task BroadcastToGroupAsync(string groupName, string method, object? message, CancellationToken cancella
 69    {
 70        try
 71        {
 072            var safe = PayloadSanitizer.Sanitize(message);
 073            await _hubContext.Clients.Group(groupName).SendAsync(method, safe, cancellationToken);
 074            _logger.Debug("Broadcasted message to group {GroupName} via method {Method}", groupName, method);
 075        }
 076        catch (Exception ex)
 77        {
 078            _logger.Error(ex, "Failed to broadcast to group {GroupName}", groupName);
 079        }
 080    }
 81}