@@ -137,6 +137,11 @@ function Get-WebSocket {
137
137
[switch ]
138
138
$Watch ,
139
139
140
+ # If set, will output the raw text of the WebSocket job.
141
+ [Alias (' Raw' )]
142
+ [switch ]
143
+ $RawText ,
144
+
140
145
# If set, will watch the output of a WebSocket job for one or more conditions.
141
146
# The conditions are the keys of the dictionary, and can be a regex, a string, or a scriptblock.
142
147
# The values of the dictionary are what will happen when a match is found.
@@ -230,15 +235,20 @@ function Get-WebSocket {
230
235
break
231
236
}
232
237
233
-
234
238
$Buf = [byte []]::new($BufferSize )
235
239
$Seg = [ArraySegment [byte ]]::new($Buf )
236
240
$null = $ws.ReceiveAsync ($Seg , $CT ).Wait()
237
241
$MessageCount ++
238
- $JS = $OutputEncoding.GetString ($Buf , 0 , $Buf.Count )
239
- if ([string ]::IsNullOrWhitespace($JS )) { continue }
240
- try {
241
- $webSocketMessage = ConvertFrom-Json $JS
242
+
243
+ try {
244
+ $webSocketMessage =
245
+ if ($Raw ) {
246
+ $OutputEncoding.GetString ($Buf , 0 , $Buf.Count )
247
+ } else {
248
+ $JS = $OutputEncoding.GetString ($Buf , 0 , $Buf.Count )
249
+ if ([string ]::IsNullOrWhitespace($JS )) { continue }
250
+ ConvertFrom-Json $JS
251
+ }
242
252
if ($handler ) {
243
253
$psCmd =
244
254
if ($runspace.LanguageMode -eq ' NoLanguage' -or
@@ -318,7 +328,7 @@ function Get-WebSocket {
318
328
}
319
329
$webSocketJob.pstypenames.insert (0 , ' WebSocketJob' )
320
330
if ($Watch ) {
321
- do {
331
+ do {
322
332
$webSocketJob | Receive-Job
323
333
Start-Sleep - Milliseconds (
324
334
7 , 11 , 13 , 17 , 19 , 23 | Get-Random
0 commit comments