@@ -16,12 +16,13 @@ function Get-WebSocket {
16
16
https://learn.microsoft.com/en-us/dotnet/api/system.net.httplistener?wt.mc_id=MVP_321542
17
17
. EXAMPLE
18
18
# Create a WebSocket job that connects to a WebSocket and outputs the results.
19
- Get-WebSocket -SocketUrl "wss://localhost:9669/"
19
+ $socketServer = Get-WebSocket -RootUrl "http://localhost:8387/" -HTML "<h1>WebSocket Server</h1>"
20
+ $socketClient = Get-WebSocket -SocketUrl "ws://localhost:8387/"
20
21
. EXAMPLE
21
22
# Get is the default verb, so we can just say WebSocket.
22
23
# `-Watch` will output a continous stream of objects from the websocket.
23
- # For example, let's Watch BlueSky, but just the text.
24
- websocket wss://jetstream2.us-west.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Watch |
24
+ # For example, let's Watch BlueSky, but just the text
25
+ websocket wss://jetstream2.us-west.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Watch -Maximum 1kb |
25
26
% {
26
27
$_.commit.record.text
27
28
}
@@ -33,14 +34,19 @@ function Get-WebSocket {
33
34
"wantedCollections=app.bsky.feed.post"
34
35
) -join '&')"
35
36
websocket $blueSkySocketUrl -Watch |
36
- % { Write-Host "$(' ' * (Get-Random -Max 10))$($_.commit.record.text)$($(' ' * (Get-Random -Max 10)))"}
37
- . EXAMPLE
37
+ % { Write-Host "$(' ' * (Get-Random -Max 10))$($_.commit.record.text)$($(' ' * (Get-Random -Max 10)))"} -Max 1kb
38
+ . EXAMPLE
39
+ # Watch continuously in a background job.
38
40
websocket wss://jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post
39
41
. EXAMPLE
40
- websocket wss://jetstream2.us-west.bsky.network/subscribe -QueryParameter @{ wantedCollections = 'app.bsky.feed.post' } -Max 1 -Debug
42
+ # Watch the first message in -Debug mode.
43
+ # This allows you to literally debug the WebSocket messages as they are encountered.
44
+ websocket wss://jetstream2.us-west.bsky.network/subscribe -QueryParameter @{
45
+ wantedCollections = 'app.bsky.feed.post'
46
+ } -Max 1 -Debug
41
47
. EXAMPLE
42
48
# Watch BlueSky, but just the emoji
43
- websocket jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Tail |
49
+ websocket jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Tail -Max 1kb |
44
50
Foreach-Object {
45
51
$in = $_
46
52
if ($in.commit.record.text -match '[\p{IsHighSurrogates}\p{IsLowSurrogates}]+') {
@@ -113,7 +119,6 @@ function Get-WebSocket {
113
119
Group |
114
120
Sort Count -Descending |
115
121
Select -First 10
116
-
117
122
#>
118
123
[CmdletBinding (
119
124
PositionalBinding = $false ,
@@ -1231,7 +1236,9 @@ function Get-WebSocket {
1231
1236
$httpListenerJob = $existingJob
1232
1237
$httpListener = $existingJob.HttpListener
1233
1238
} else {
1234
- $httpListenerJob = Start-ThreadJob - ScriptBlock $SocketServerJob - Name " $RootUrl " - ArgumentList $Variable @StartThreadJobSplat
1239
+ $httpListenerJob = Start-ThreadJob - ScriptBlock $SocketServerJob - Name " $RootUrl " - ArgumentList $Variable @StartThreadJobSplat
1240
+ $httpListenerJob.pstypenames.insert (0 , ' WebSocket.ThreadJob' )
1241
+ $httpListenerJob.pstypenames.insert (0 , ' WebSocket.Server.ThreadJob' )
1235
1242
}
1236
1243
}
1237
1244
@@ -1322,6 +1329,7 @@ function Get-WebSocket {
1322
1329
)
1323
1330
}
1324
1331
$webSocketJob.pstypenames.insert (0 , ' WebSocket.ThreadJob' )
1332
+ $webSocketJob.pstypenames.insert (0 , ' WebSocket.Client.ThreadJob' )
1325
1333
}
1326
1334
1327
1335
# If we're broadcasting a message
0 commit comments