-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
StartAutomating
authored and
StartAutomating
committed
May 28, 2023
1 parent
77372a6
commit 9b55425
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
function Set-OBSRecordDirectory { | ||
<# | ||
.Synopsis | ||
Set-OBSRecordDirectory : SetRecordDirectory | ||
.Description | ||
Sets the current directory that the record output writes files to. | ||
Set-OBSRecordDirectory calls the OBS WebSocket with a request of type SetRecordDirectory. | ||
.Link | ||
https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#setrecorddirectory | ||
#> | ||
[Reflection.AssemblyMetadata('OBS.WebSocket.RequestType', 'SetRecordDirectory')] | ||
param( | ||
<# Output directory #> | ||
[Parameter(Mandatory,ValueFromPipelineByPropertyName)] | ||
[ComponentModel.DefaultBindingProperty('recordDirectory')] | ||
[string] | ||
$RecordDirectory, | ||
# If set, will return the information that would otherwise be sent to OBS. | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[Alias('OutputRequest','OutputInput')] | ||
[switch] | ||
$PassThru | ||
) | ||
process { | ||
# Create a copy of the parameters (that are part of the payload) | ||
$paramCopy = [Ordered]@{} | ||
# get a reference to this command | ||
$myCmd = $MyInvocation.MyCommand | ||
# Keep track of how many requests we have done of a given type | ||
# (this makes creating RequestIDs easy) | ||
if (-not $script:ObsRequestsCounts) { | ||
$script:ObsRequestsCounts = @{} | ||
} | ||
# Set my requestType to blank | ||
$myRequestType = '' | ||
# and indicate we are not expecting a response | ||
$responseExpected = $false | ||
# Then walk over this commands' attributes, | ||
foreach ($attr in $myCmd.ScriptBlock.Attributes) { | ||
if ($attr -is [Reflection.AssemblyMetadataAttribute]) { | ||
if ($attr.Key -eq 'OBS.WebSocket.RequestType') { | ||
$myRequestType = $attr.Value # set the requestType, | ||
} | ||
elseif ($attr.Key -eq 'OBS.WebSocket.ExpectingResponse') { | ||
# and determine if we are expecting a response. | ||
$responseExpected = | ||
if ($attr.Value -eq 'false') { | ||
$false | ||
} else { $true } | ||
} | ||
} | ||
} | ||
# Walk over each parameter | ||
:nextParam foreach ($keyValue in $PSBoundParameters.GetEnumerator()) { | ||
# and walk over each of it's attributes to see if it part of the payload | ||
foreach ($attr in $myCmd.Parameters[$keyValue.Key].Attributes) { | ||
# If the parameter is bound to part of the payload | ||
if ($attr -is [ComponentModel.DefaultBindingPropertyAttribute]) { | ||
# copy it into our payload dicitionary. | ||
$paramCopy[$attr.Name] = $keyValue.Value | ||
# (don't forget to turn switches into booleans) | ||
if ($paramCopy[$attr.Name] -is [switch]) { | ||
$paramCopy[$attr.Name] = [bool]$paramCopy[$attr.Name] | ||
} | ||
if ($attr.Name -like '*path') { | ||
$paramCopy[$attr.Name] = | ||
"$($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($paramCopy[$attr.Name]))" | ||
} | ||
continue nextParam | ||
} | ||
} | ||
} | ||
|
||
# and make a request ID from that. | ||
$myRequestId = "$myRequestType.$([Guid]::newGuid())" | ||
|
||
# Construct the payload object | ||
$requestPayload = [Ordered]@{ | ||
# It must include a request ID | ||
requestId = $myRequestId | ||
# request type | ||
requestType = $myRequestType | ||
# and optional data | ||
requestData = $paramCopy | ||
} | ||
if ($PassThru) { | ||
[PSCustomObject]$requestPayload | ||
} else { | ||
[PSCustomObject]$requestPayload | | ||
Send-OBS | ||
} | ||
} | ||
} | ||
|