Skip to content

Commit

Permalink
Version 2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tinodo committed Feb 19, 2024
1 parent ae9f78c commit cff4052
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 13 deletions.
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>2.0.1</Version>
<Version>2.0.2</Version>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

Expand Down
79 changes: 69 additions & 10 deletions OBSClient/ObsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public partial class ObsClient : INotifyPropertyChanged, IDisposable

private int _sessionMessagesSent = 0;

private int _maxRequestRetries = 10;

private int _requestRetryInterval = 500;

/// <summary>
/// Gets or sets the maximum amount of time, in milliseconds, the <see cref="ObsClient"/> to wait for an OBS Studio response after making a request.
/// </summary>
Expand Down Expand Up @@ -269,6 +273,47 @@ public int SessionMessagesReceived
}
}

/// <summary>
/// Gets or sets the maximum number of times the <see cref="ObsClient"/> should retry a request when OBS Studio is not ready to perform the request.
/// </summary>
/// <remarks>
/// This typically occurs when OBS Studio is not ready to perform the request, e.g. when it is still starting up. It will authenticate the client, but not yet accept requests.
/// </remarks>
public int MaxRequestRetries
{
get
{
return this._maxRequestRetries;
}
set
{
if (this._maxRequestRetries != value && value >= 0)
{
this._maxRequestRetries = value;
this.OnPropertyChanged();
}
}
}

/// <summary>
/// Gets or sets the interval, in milliseconds, the <see cref="ObsClient"/> should wait before retrying a request when OBS Studio is not ready to perform the request.
/// </summary>
public int RequestRetryInterval
{
get
{
return this._requestRetryInterval;
}
set
{
if (this._requestRetryInterval != value && value >= 0)
{
this._requestRetryInterval = value;
this.OnPropertyChanged();
}
}
}

/// <summary>
/// Asynchronous event, triggered when the connection with OBS Studio is closed.
/// </summary>
Expand Down Expand Up @@ -462,6 +507,7 @@ protected virtual void Dispose(bool disposing)
{
this.Disconnect();
this._client.Dispose();
this._receiver.Dispose();
}

this._requests.Clear();
Expand Down Expand Up @@ -778,23 +824,36 @@ private async Task<T> SendRequestAsync<T>(object? requestData = null, [CallerMem

private async Task<RequestResponseMessage> SendRequestAndWaitAsync(string requestType, object? requestData = null)
{
var requestId = Guid.NewGuid().ToString();
var d = new { requestType, requestId, requestData };
var op = (int)OpCode.Request;
var result = await this.SendAndWaitAsync(new { d, op });
if (result is RequestResponseMessage requestResponseData)
int retryCount = 0;
while (true)
{
if (requestResponseData.RequestStatus.Result)
var requestId = Guid.NewGuid().ToString();
var d = new { requestType, requestId, requestData };
var op = (int)OpCode.Request;
var result = await this.SendAndWaitAsync(new { d, op });
if (result is RequestResponseMessage requestResponseData)
{
return requestResponseData;
if (requestResponseData.RequestStatus.Result)
{
return requestResponseData;
}
else
{
if (requestResponseData.RequestStatus.Code == RequestStatusCode.NotReady && retryCount++ < this._maxRequestRetries)
{
Thread.Sleep(this._requestRetryInterval);
}
else
{
throw new ObsResponseException(requestResponseData.RequestStatus);
}
}
}
else
{
throw new ObsResponseException(requestResponseData.RequestStatus);
throw new ObsClientException($"Unexpected response type {result?.GetType().Name} for request {requestId} in {MethodBase.GetCurrentMethod()?.Name}");
}
}

throw new ObsClientException($"Unexpected response type {result?.GetType().Name} for request {requestId} in {MethodBase.GetCurrentMethod()?.Name}");
}

private void ReconnectTimerCallback(object? state)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Our intent is to create a <ins>complete</ins> and <ins>easy to use</ins> client

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

## Sample usage

Expand Down

0 comments on commit cff4052

Please sign in to comment.