< Summary - Kestrun — Combined Coverage

Information
Class: Public.SignalR.Send-KrSignalREvent
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/SignalR/Send-KrSignalREvent.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 68
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/12) Total lines: 68 Tag: Kestrun/Kestrun@c33ec02a85e4f8d6061aeaab5a5e8c3a8b665594

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/SignalR/Send-KrSignalREvent.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Broadcasts a custom event to all connected SignalR clients.
 4    .DESCRIPTION
 5        This function sends a custom event with optional data to all connected SignalR clients via the IRealtimeBroadcas
 6        The event is broadcast in real-time to all connected clients listening on the hub.
 7    .PARAMETER EventName
 8        The name of the event to broadcast.
 9    .PARAMETER Data
 10        Optional data to include with the event. Can be any object that will be serialized to JSON.
 11    .PARAMETER Server
 12        The Kestrun server instance. If not specified, the default server is used.
 13    .EXAMPLE
 14        Send-KrSignalREvent -EventName "UserLoggedIn" -Data @{ Username = "admin"; Timestamp = (Get-Date) }
 15        Broadcasts a custom event with data to all connected SignalR clients.
 16    .EXAMPLE
 17        Send-KrSignalREvent -EventName "ServerHealthCheck" -Data @{ Status = "Healthy"; Uptime = 3600 }
 18        Broadcasts a health check event with status information.
 19    .EXAMPLE
 20        Get-KrServer | Send-KrSignalREvent -EventName "TaskCompleted" -Data @{ TaskId = 123; Success = $true }
 21        Broadcasts a task completion event using the pipeline.
 22    .NOTES
 23        This function requires that SignalR has been configured on the server using Add-KrSignalRHubMiddleware.
 24        The IRealtimeBroadcaster service must be registered for this cmdlet to work.
 25#>
 26function Send-KrSignalREvent {
 27    [KestrunRuntimeApi('Everywhere')]
 28    [CmdletBinding()]
 29    param(
 30        [Parameter(Mandatory = $true)]
 31        [string]$EventName,
 32
 33        [Parameter()]
 34        [object]$Data,
 35
 36        [Parameter(ValueFromPipeline)]
 37        [Kestrun.Hosting.KestrunHost]$Server
 38    )
 39
 40    process {
 41        try {
 042            if ($null -ne $Context) {
 43                # Prefer the centralized KestrunContext implementation when inside a route
 044                if ($Context.BroadcastEvent($EventName, $Data, [System.Threading.CancellationToken]::None)) {
 045                    Write-KrLog -Level Debug -Message "Broadcasted event: $EventName - $Data"
 46                    return
 47                } else {
 048                    Write-KrLog -Level Error -Message 'Failed to broadcast event: Unknown error'
 49                    return
 50                }
 51            }
 52
 53            # Fallback: allow explicit host usage outside a route (no HttpContext)
 054            if (-not $Server) {
 055                try { $Server = Get-KrServer } catch { $Server = $null }
 56            }
 057            if ($null -ne $Server) {
 058                $task = [Kestrun.Hosting.KestrunHostSignalRExtensions]::BroadcastEventAsync($Server, $EventName, $Data, 
 059                $null = $task.GetAwaiter().GetResult()
 060                Write-KrLog -Level Debug -Message "Broadcasted event (host fallback): $EventName - $Data"
 61            } else {
 062                Write-KrOutsideRouteWarning
 63            }
 64        } catch {
 065            Write-KrLog -Level Error -Message "Failed to broadcast event: $_" -Exception $_.Exception
 66        }
 67    }
 68}

Methods/Properties

Send-KrSignalREvent()