Skip to content

Commit

Permalink
feat: Get-WebSocket SupportsPaging ( Fixes #55 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Jan 5, 2025
1 parent d7954e2 commit 305649e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Commands/Get-WebSocket.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function Get-WebSocket {
Sort Count -Descending |
Select -First 10
#>
[CmdletBinding(PositionalBinding=$false)]
[CmdletBinding(PositionalBinding=$false,SupportsPaging)]
[Alias('WebSocket')]
param(
# The Uri of the WebSocket to connect to.
Expand Down Expand Up @@ -295,6 +295,7 @@ function Get-WebSocket {

$MessageCount = [long]0
$FilteredCount = [long]0
$SkipCount = [long]0

:WebSocketMessageLoop while ($true) {
if ($ws.State -ne 'Open') {break }
Expand All @@ -303,7 +304,9 @@ function Get-WebSocket {
break
}

if ($Maximum -and $MessageCount -ge $Maximum) {
if ($Maximum -and (
($MessageCount - $FilteredCount) -ge $Maximum
)) {
$ws.CloseAsync([Net.WebSockets.WebSocketCloseStatus]::NormalClosure, 'Maximum messages reached', $CT).Wait()
break
}
Expand Down Expand Up @@ -347,7 +350,16 @@ function Get-WebSocket {
}
}
}
if ($Skip -and ($SkipCount -le $Skip)) {
$SkipCount++
continue WebSocketMessageLoop
}


$MessageObject
if ($First -and ($MessageCount - $FilteredCount - $SkipCount) -ge $First) {
$Maximum = $first
}
}
}
if ($PSTypeName) {
Expand Down

0 comments on commit 305649e

Please sign in to comment.