@@ -30,6 +30,8 @@ function Get-WebSocket {
3030 % { Write-Host "$(' ' * (Get-Random -Max 10))$($_.commit.record.text)$($(' ' * (Get-Random -Max 10)))"}
3131 . EXAMPLE
3232 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
3335 . EXAMPLE
3436 # Watch BlueSky, but just the emoji
3537 websocket jetstream2.us-east.bsky.network/subscribe?wantedCollections=app.bsky.feed.post -Tail |
@@ -112,6 +114,11 @@ function Get-WebSocket {
112114 [Alias (' Url' , ' Uri' )]
113115 [uri ]$WebSocketUri ,
114116
117+ # A collection of query parameters.
118+ # These will be appended onto the `-WebSocketUri`.
119+ [Collections.IDictionary ]
120+ $QueryParameter ,
121+
115122 # A ScriptBlock that will handle the output of the WebSocket.
116123 [ScriptBlock ]
117124 $Handler ,
@@ -227,6 +234,7 @@ function Get-WebSocket {
227234 param (
228235 # By accepting a single parameter containing variables,
229236 # 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.
230238 [Collections.IDictionary ]$Variable
231239 )
232240
@@ -241,7 +249,20 @@ function Get-WebSocket {
241249
242250 if (-not $WebSocketUri.Scheme ) {
243251 $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+ }
245266
246267 if (-not $BufferSize ) {
247268 $BufferSize = 64 kb
0 commit comments