@@ -23,10 +23,22 @@ function Get-WebSocket {
23
23
websocket jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Tail |
24
24
Foreach-Object {
25
25
$in = $_
26
+ $spacing = (' ' * (Get-Random -Minimum 0 -Maximum 7))
26
27
if ($in.commit.record.text -match "(?>(?:$emojiPattern|\#\w+)") {
27
- Write-Host $matches.0 -NoNewline
28
+ $match = $matches.0
29
+ Write-Host $spacing,$match,$spacing -NoNewline
28
30
}
29
31
}
32
+ . EXAMPLE
33
+ websocket wss://jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Watch |
34
+ Where-Object {
35
+ $_.commit.record.embed.'$type' -eq 'app.bsky.embed.external'
36
+ } |
37
+ Foreach-Object {
38
+ $_.commit.record.embed.external.uri
39
+ }
40
+ . EXAMPLE
41
+
30
42
#>
31
43
[CmdletBinding (PositionalBinding = $false )]
32
44
param (
@@ -77,6 +89,10 @@ function Get-WebSocket {
77
89
[switch ]
78
90
$Watch ,
79
91
92
+ # The timeout for the WebSocket connection. If this is provided, after the timeout elapsed, the WebSocket will be closed.
93
+ [TimeSpan ]
94
+ $TimeOut ,
95
+
80
96
# The maximum time to wait for a connection to be established.
81
97
# By default, this is 7 seconds.
82
98
[TimeSpan ]
@@ -123,11 +139,16 @@ function Get-WebSocket {
123
139
$ws = $WebSocket
124
140
}
125
141
142
+ $webSocketStartTime = $Variable.WebSocketStartTime = [DateTime ]::Now
126
143
$Variable.WebSocket = $ws
127
144
128
145
129
146
while ($true ) {
130
147
if ($ws.State -ne ' Open' ) {break }
148
+ if ($TimeOut -and ([DateTime ]::Now - $webSocketStartTime ) -gt $TimeOut ) {
149
+ $ws.CloseAsync ([Net.WebSockets.WebSocketCloseStatus ]::NormalClosure, ' Timeout' , $CT ).Wait()
150
+ break
151
+ }
131
152
$Buf = [byte []]::new($BufferSize )
132
153
$Seg = [ArraySegment [byte ]]::new($Buf )
133
154
$null = $ws.ReceiveAsync ($Seg , $CT ).Wait()
0 commit comments