Skip to content

Commit c5175af

Browse files
author
James Brundage
committed
feat: Get-WebSocket -SubProtocol ( Fixes #46 )
1 parent de52d35 commit c5175af

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Commands/Get-WebSocket.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ function Get-WebSocket {
165165
[switch]
166166
$Binary,
167167

168+
# The subprotocol used by the websocket. If not provided, this will default to `json`.
169+
[string]
170+
$SubProtocol,
171+
168172
# If set, will watch the output of a WebSocket job for one or more conditions.
169173
# The conditions are the keys of the dictionary, and can be a regex, a string, or a scriptblock.
170174
# The values of the dictionary are what will happen when a match is found.
@@ -242,6 +246,11 @@ function Get-WebSocket {
242246

243247
if (-not $webSocket) {
244248
$ws = [Net.WebSockets.ClientWebSocket]::new()
249+
if ($SubProtocol) {
250+
$ws.Options.AddSubProtocol($SubProtocol)
251+
} else {
252+
$ws.Options.AddSubProtocol('json')
253+
}
245254
$null = $ws.ConnectAsync($WebSocketUri, $CT).Wait()
246255
} else {
247256
$ws = $WebSocket

0 commit comments

Comments
 (0)