Skip to content

Commit

Permalink
refactoring ReceiverAsync and CloseConnectionAsync to reduce cognitiv…
Browse files Browse the repository at this point in the history
…e complexity.
  • Loading branch information
tinodo committed Oct 30, 2023
1 parent bc8bf42 commit d2aef41
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions OBSClient/ObsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,14 @@ private async Task ReceiverAsync(CancellationToken ct)
}
}

await this.CloseConnectionAsync(ct.IsCancellationRequested);
}

private async Task CloseConnectionAsync(bool closeRequested)
{
WebSocketCloseCode closeCode;
string closeDescription;
if (ct.IsCancellationRequested)
if (closeRequested)
{
// Closed the connection because you called Disconnect().
closeCode = WebSocketCloseCode.NormalClosure;
Expand All @@ -678,11 +683,6 @@ private async Task ReceiverAsync(CancellationToken ct)
closeDescription = this._client.CloseStatusDescription ?? "Unknown";
}

await this.CloseConnectionAsync(closeCode, closeDescription);
}

private async Task CloseConnectionAsync(WebSocketCloseCode closeCode, string closeDescription)
{
if (this._client.State == WebSocketState.Open || this._client.State == WebSocketState.CloseReceived)
{
this.ConnectionState = ConnectionState.Disconnecting;
Expand All @@ -699,7 +699,6 @@ private async Task CloseConnectionAsync(WebSocketCloseCode closeCode, string clo
{
this._authenticationComplete.SetResult(false);
}

}

private async Task<IMessage> SendAndWaitAsync(dynamic request)
Expand Down

0 comments on commit d2aef41

Please sign in to comment.