@@ -62,11 +62,13 @@ function Get-WebSocket {
6262 }
6363 . EXAMPLE
6464 # BlueSky, but just the hashtags
65- websocket wss://jetstream2.us-west.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -WatchFor @{
65+ websocket wss://jetstream2.us-west.bsky.network/subscribe -QueryParameter @{
66+ wantedCollections = 'app.bsky.feed.post'
67+ } -WatchFor @{
6668 {$webSocketoutput.commit.record.text -match "\#\w+"}={
6769 $matches.0
6870 }
69- }
71+ } -Maximum 1kb
7072 . EXAMPLE
7173 # BlueSky, but just the hashtags (as links)
7274 websocket wss://jetstream2.us-west.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -WatchFor @{
@@ -191,6 +193,13 @@ function Get-WebSocket {
191193 [ScriptBlock ]
192194 $Handler ,
193195
196+ # If set, will forward websocket messages as events.
197+ # Only events that match -Filter will be forwarded.
198+ [Parameter (ValueFromPipelineByPropertyName , ParameterSetName = ' WebSocketClient' )]
199+ [Alias (' Forward' )]
200+ [switch ]
201+ $ForwardEvent ,
202+
194203 # Any variables to declare in the WebSocket job.
195204 # These variables will also be added to the job as properties.
196205 [Collections.IDictionary ]
@@ -434,7 +443,7 @@ function Get-WebSocket {
434443 if ($RawText ) {
435444 $messageString
436445 } else {
437- $MessageObject = ConvertFrom-Json - InputObject $messageString
446+ $MessageObject = ConvertFrom-Json - InputObject $messageString
438447 if ($filter ) {
439448 foreach ($fil in $Filter ) {
440449 if ($fil -is [ScriptBlock ] -or
@@ -452,7 +461,19 @@ function Get-WebSocket {
452461 continue WebSocketMessageLoop
453462 }
454463
455- $MessageObject
464+ $MessageObject
465+
466+ # If we are forwarding events
467+ if ($ForwardEvent -and $MainRunspace.Events.GenerateEvent ) {
468+ # generate an event in the main runspace
469+ $null = $MainRunspace.Events.GenerateEvent (
470+ " $SocketUrl " ,
471+ $ws ,
472+ @ ($MessageObject ),
473+ $MessageObject
474+ )
475+ }
476+
456477 if ($First -and ($MessageCount - $FilteredCount - $SkipCount ) -ge $First ) {
457478 $Maximum = $first
458479 }
0 commit comments