@@ -30,6 +30,8 @@ function Get-WebSocket {
30
30
% { Write-Host "$(' ' * (Get-Random -Max 10))$($_.commit.record.text)$($(' ' * (Get-Random -Max 10)))"}
31
31
. EXAMPLE
32
32
websocket wss://jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post
33
+ . EXAMPLE
34
+ websocket wss://jetstream2.us-west.bsky.network/subscribe -QueryParameter @{ wantedCollections = 'app.bsky.feed.post' } -Max 1 -Debug
33
35
. EXAMPLE
34
36
# Watch BlueSky, but just the emoji
35
37
websocket jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Tail |
@@ -112,6 +114,11 @@ function Get-WebSocket {
112
114
[Alias (' Url' , ' Uri' )]
113
115
[uri ]$WebSocketUri ,
114
116
117
+ # A collection of query parameters.
118
+ # These will be appended onto the `-WebSocketUri`.
119
+ [Collections.IDictionary ]
120
+ $QueryParameter ,
121
+
115
122
# A ScriptBlock that will handle the output of the WebSocket.
116
123
[ScriptBlock ]
117
124
$Handler ,
@@ -227,6 +234,7 @@ function Get-WebSocket {
227
234
param (
228
235
# By accepting a single parameter containing variables,
229
236
# we can avoid the need to pass in a large number of parameters.
237
+ # we can also modify this dictionary, to provide a way to pass information back.
230
238
[Collections.IDictionary ]$Variable
231
239
)
232
240
@@ -241,7 +249,20 @@ function Get-WebSocket {
241
249
242
250
if (-not $WebSocketUri.Scheme ) {
243
251
$WebSocketUri = [uri ]" wss://$WebSocketUri "
244
- }
252
+ }
253
+
254
+ if ($QueryParameter ) {
255
+ $WebSocketUri = [uri ]" $ ( $webSocketUri ) $ ( $WebSocketUri.Query ? ' &' : ' ?' ) $ ( @ (
256
+ foreach ($keyValuePair in $QueryParameter.GetEnumerator ()) {
257
+ if ($keyValuePair.Value -is [Collections.IList ]) {
258
+ foreach ($value in $keyValuePair.Value ) {
259
+ " $ ( $keyValuePair.Key ) =$ ( [Web.HttpUtility ]::UrlEncode($value ).Replace(' +' , ' %20' )) "
260
+ }
261
+ } else {
262
+ " $ ( $keyValuePair.Key ) =$ ( [Web.HttpUtility ]::UrlEncode($keyValuePair.Value ).Replace(' +' , ' %20' )) "
263
+ }
264
+ }) -join ' &' ) "
265
+ }
245
266
246
267
if (-not $BufferSize ) {
247
268
$BufferSize = 64 kb
0 commit comments