Skip to content

Commit

Permalink
Fixed issues with ToggleRecord and ToggleRecordPause #4
Browse files Browse the repository at this point in the history
  • Loading branch information
tinodo committed Oct 23, 2023
1 parent b6cc9ca commit 0fc5f6e
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 21 deletions.
4 changes: 2 additions & 2 deletions OBSClient/MessageClasses/RequestResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ public void OnDeserialized()

// Record Requests
RequestType.GetRecordStatus => this.RawResponseData.Value.Deserialize<RecordStatusResponse>(),
RequestType.ToggleRecord => null,
RequestType.ToggleRecord => this.RawResponseData.Value.Deserialize<OutputActiveResponse>(),
RequestType.StartRecord => null,
RequestType.StopRecord => this.RawResponseData.Value.Deserialize<OutputPathResponse>(),
RequestType.ToggleRecordPause => null,
RequestType.ToggleRecordPause => this.RawResponseData.Value.Deserialize<OutputPausedResponse>(),
RequestType.PauseRecord => null,
RequestType.ResumeRecord => null,

Expand Down
2 changes: 1 addition & 1 deletion OBSClient/Messages/OutputActiveResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/// <summary>
/// Provides the Response Data (<see cref="IResponse"/>) in the Response Message (<see cref="IMessage"/>) returned by OBS Studio after sending a successful request of any of these types:
/// GetVirtualCamStatus, ToggleVirtualCam, GetReplayBufferStatus, ToggleReplayBuffer, ToggleOutput and ToggleStream.
/// GetVirtualCamStatus, ToggleVirtualCam, ToggleRecord, GetReplayBufferStatus, ToggleReplayBuffer, ToggleOutput and ToggleStream.
/// </summary>
public class OutputActiveResponse : IResponse
{
Expand Down
27 changes: 27 additions & 0 deletions OBSClient/Messages/OutputPausedResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace OBSStudioClient.Messages
{
using OBSStudioClient.Interfaces;
using System.Text.Json.Serialization;

/// <summary>
/// Provides the Response Data (<see cref="IResponse"/>) in the Response Message (<see cref="IMessage"/>) returned by OBS Studio after sending a successful ToggleRecordPaused request.
/// </summary>
public class OutputPausedResponse : IResponse
{
/// <summary>
/// Gets a value indicating whether the output is active.
/// </summary>
[JsonPropertyName("outputPaused")]
public bool OutputPaused { get; }

/// <summary>
/// Initializes a new instance of the <see cref="OutputPausedResponse"/> class.
/// </summary>
/// <param name="outputPaused">a value indicating whether the output is paused.</param>
[JsonConstructor]
public OutputPausedResponse(bool outputPaused)
{
this.OutputPaused = outputPaused;
}
}
}
2 changes: 1 addition & 1 deletion OBSClient/OBSClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<RepositoryType>git</RepositoryType>
<PackageTags>obs</PackageTags>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>1.2.1</Version>
<Version>1.3.0</Version>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

Expand Down
8 changes: 4 additions & 4 deletions OBSClient/ObsClient_RecordRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public async Task<RecordStatusResponse> GetRecordStatus()
/// <summary>
/// Toggles the status of the record output.
/// </summary>
public async Task ToggleRecord()
public async Task<bool> ToggleRecord()
{
await this.SendRequestAsync();
return (await this.SendRequestAsync<OutputActiveResponse>()).OutputActive;
}

/// <summary>
Expand All @@ -41,9 +41,9 @@ public async Task<string> StopRecord()
/// <summary>
/// Toggles pause on the record output.
/// </summary>
public async Task ToggleRecordPause()
public async Task<bool> ToggleRecordPause()
{
await this.SendRequestAsync();
return (await this.SendRequestAsync<OutputPausedResponse>()).OutputPaused;
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# ObsClient
A Complete cross platform .NET WebSocket Client for OBS Studio version 28 and up.
Currently implementing: [**obs-websocket 5.1.0 Protocol**](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md)
Currently implementing: [**obs-websocket 5.3.0 Protocol**](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md)

## Installation
Install from the [NuGet Gallery](https://www.nuget.org/packages/OBSClient)
Or through the NuGet CLI: `NuGet\Install-Package OBSClient -Version 1.2.1`
From the command line: `dotnet add package OBSClient --version 1.2.1`
Or through the NuGet CLI: `NuGet\Install-Package OBSClient -Version 1.3.0`
From the command line: `dotnet add package OBSClient --version 1.3.0`

## Sample usage
```
Expand Down
135 changes: 126 additions & 9 deletions SampleWindowsAppliation/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 62 additions & 1 deletion SampleWindowsAppliation/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public partial class Form1 : Form
private delegate void SafeListboxRemove(object itemToRemove, ListBox listBox);
private delegate void SafeListboxRefresh(ListBox listBox);
private delegate void SafeUpdateTitle();
private delegate void SafeUpdateRecordState(string text);
private const string Title = "Obs Client";
public Form1()
{
Expand Down Expand Up @@ -245,6 +246,8 @@ private Task ReplayBufferSaved(object? sender, ReplayBufferSavedEventArgs e)

private Task RecordStateChanged(object? sender, RecordStateChangedEventArgs e)
{
var active = e.OutputActive ? "Active" : "Inactive";
RefreshRecordState($"{e.OutputState} ({active})");
return Task.CompletedTask;
}

Expand Down Expand Up @@ -424,6 +427,19 @@ private void RefreshListbox(ListBox listBox)
}
}

private void RefreshRecordState(string text)
{
if (lblRecordState.InvokeRequired)
{
var d = new SafeUpdateRecordState(RefreshRecordState);
lblRecordState.Invoke(d, new object[] { text });
}
else
{
lblRecordState.Text = text;
}
}

private async void button1_Click(object sender, EventArgs e)
{
var result = await _client.ConnectAsync(this.tbPassword.Text, this.tbHostname.Text, Convert.ToInt32(this.nudPort.Value));
Expand Down Expand Up @@ -689,7 +705,7 @@ private async void bnGetStreamStatus_Click(object sender, EventArgs e)
var response = await _client.GetStreamStatus();
var result = string.Empty;
result += $"OutputActive: {response.OutputActive}" + Environment.NewLine;
result += $"OutputActive: {response.OutputBytes}" + Environment.NewLine;
result += $"OutputBytes: {response.OutputBytes}" + Environment.NewLine;
result += $"OutputCongestion: {response.OutputCongestion}" + Environment.NewLine;
result += $"OutputDuration: {response.OutputDuration}" + Environment.NewLine;
result += $"OutputReconnecting: {response.OutputReconnecting}" + Environment.NewLine;
Expand All @@ -698,5 +714,50 @@ private async void bnGetStreamStatus_Click(object sender, EventArgs e)
result += $"OutputTotalFrames: {response.OutputTotalFrames}" + Environment.NewLine;
MessageBox.Show(result, "GetStreamStatus");
}

private async void btnGetRecordStatus_Click(object sender, EventArgs e)
{
var response = await _client.GetRecordStatus();
var result = string.Empty;
result += $"OutputActive: {response.OutputActive}" + Environment.NewLine;
result += $"OutputBytes: {response.OutputBytes}" + Environment.NewLine;
result += $"OutputDuration: {response.OutputDuration}" + Environment.NewLine;
result += $"OutputPaused: {response.OutputPaused}" + Environment.NewLine;
result += $"OutputTimecode: {response.OutputTimecode}" + Environment.NewLine;
MessageBox.Show(result, "GetRecordStatus");
}

private async void btnToggleRecord_Click(object sender, EventArgs e)
{
var result = await _client.ToggleRecord();
MessageBox.Show(result.ToString(), "ToggleRecord");
}

private async void btnStartRecord_Click(object sender, EventArgs e)
{
await _client.StartRecord();
}

private async void btnStopRecord_Click(object sender, EventArgs e)
{
var result = await _client.StopRecord();
MessageBox.Show(result, "StopRecord");
}

private async void btnToggleRecordPause_Click(object sender, EventArgs e)
{
var result = await _client.ToggleRecordPause();
MessageBox.Show(result.ToString(), "ToggleRecordPause");
}

private async void btnPauseRecord_Click(object sender, EventArgs e)
{
await _client.PauseRecord();
}

private async void btnResumeRecord_Click(object sender, EventArgs e)
{
await _client.ResumeRecord();
}
}
}

0 comments on commit 0fc5f6e

Please sign in to comment.