@@ -38,14 +38,12 @@ function Watch-OBS
3838 begin {
3939 $obsWatcherJobDefinition = ' ' + {
4040 param (
41- [uri ]$webSocketUri ,
42-
43- [Alias (' WebSocketPassword' )]
44- $WebSocketToken ,
45-
46- [int ]
47- $BufferSize = 64 kb
41+ [Collections.IDictionary ]$Variable
4842 )
43+
44+ foreach ($keyValue in $Variable.GetEnumerator ()) {
45+ $ExecutionContext.SessionState.PSVariable.Set ($keyValue.Name , $keyValue.Value )
46+ }
4947 }.ToString() +
5048"
5149function Receive-OBS {
@@ -76,6 +74,7 @@ $($ExecutionContext.SessionState.InvokeCommand.GetCommand('Send-OBS', 'Function'
7674 $script :ObsConnections = @ {}
7775 }
7876 $script :ObsConnections [$webSocketUri ] = $Websocket
77+ $Variable [' WebSocket' ] = $Websocket
7978
8079 [PSCustomObject ][Ordered ]@ {
8180 PSTypename = ' obs.websocket'
@@ -101,11 +100,21 @@ $($ExecutionContext.SessionState.InvokeCommand.GetCommand('Send-OBS', 'Function'
101100
102101 if ($msg ) {
103102 $messageData = try { ConvertFrom-Json $msg - ErrorAction Ignore} catch { $_ }
104- if ($messageData -isnot [Management.Automation.ErrorRecord ]) {
105- $messageData | Receive-OBS - WebSocketToken $WebSocketToken - WebSocketUri $webSocketUri - SendEvent
103+ $received = if ($messageData -isnot [Management.Automation.ErrorRecord ]) {
104+ $messageData | Receive-OBS - WebSocketToken $WebSocketToken - WebSocketUri $webSocketUri - SendEvent - Subscription $Subscription
106105 } else {
107106 $messageData
108107 }
108+ if ($MainRunspace ) {
109+ foreach ($receivedItem in $received ) {
110+ if ($receivedItem -is [Management.Automation.PSEvent ]) {
111+ $MainRunspace.Events.GenerateEvent ($receivedItem.SourceIdentifier , $receivedItem.Sender , $receivedItem.SourceArgs , $receivedItem.MessageData )
112+ } else {
113+ $MainRunspace.Events.GenerateEvent (' obs://' , $Websocket , $received , $null )
114+ }
115+ }
116+ }
117+ $received
109118 }
110119
111120 $buffer.Clear ()
@@ -133,9 +142,14 @@ $($ExecutionContext.SessionState.InvokeCommand.GetCommand('Send-OBS', 'Function'
133142
134143 process {
135144
136-
145+ $MainRunspace = [ Runspace ]::DefaultRunspace
137146 $obsWatcher =
138- Start-ThreadJob - ScriptBlock $obsWatcherJobDefinition - Name " OBS.Connection.$ ( $Credential.UserName ) " - ArgumentList $WebSocketURI , $WebSocketToken , $BufferSize
147+ Start-ThreadJob - ScriptBlock $obsWatcherJobDefinition - Name " OBS.Connection.$ ( $Credential.UserName ) " - ArgumentList ([Ordered ]@ {
148+ WebSocketURI = $WebSocketURI
149+ WebSocketToken = $WebSocketToken
150+ BufferSize = $BufferSize
151+ MainRunspace = $MainRunspace
152+ })
139153
140154 $whenOutputAddedHandler =
141155 Register-ObjectEvent - InputObject $obsWatcher.Output - EventName DataAdded - Action {
0 commit comments