< 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@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 10
Coverable lines: 10
Total lines: 66
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@c33ec02a85e4f8d6061aeaab5a5e8c3a8b66559412/18/2025 - 21:41:58 Line coverage: 0% (0/10) Total lines: 66 Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff

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)) {
 45                    return
 46                } else {
 047                    Write-KrLog -Level Error -Message 'Failed to broadcast event: Unknown error'
 48                    return
 49                }
 50            }
 51
 52            # Fallback: allow explicit host usage outside a route (no HttpContext)
 053            if (-not $Server) {
 054                try { $Server = Get-KrServer } catch { $Server = $null }
 55            }
 056            if ($null -ne $Server) {
 057                $task = [Kestrun.Hosting.KestrunHostSignalRExtensions]::BroadcastEventAsync($Server, $EventName, $Data, 
 058                $null = $task.GetAwaiter().GetResult()
 59            } else {
 060                Write-KrOutsideRouteWarning
 61            }
 62        } catch {
 063            Write-KrLog -Level Error -Message 'Failed to broadcast event: {error}' -Values $_.Exception.Message -Excepti
 64        }
 65    }
 66}

Methods/Properties

Send-KrSignalREvent()