Skip to content

Commit

Permalink
fixed startup exception if teams is not running
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyeao committed Dec 17, 2023
1 parent 56e27dc commit 16d9ad6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions API/Teams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class WebSocketClient
{
#region Private Fields

private readonly ClientWebSocket _clientWebSocket;
private ClientWebSocket _clientWebSocket;
private readonly string _settingsFilePath;
private readonly State _state;
private readonly Action<string> _updateTokenAction;
Expand Down Expand Up @@ -316,17 +316,21 @@ private async Task ReconnectAsync()
int retryDelay = 2000; // milliseconds
int retryCount = 0;

while (retryCount < maxRetryCount && !IsConnected)
while (retryCount < maxRetryCount)
{
try
{
Log.Debug($"Attempting reconnection, try {retryCount + 1} of {maxRetryCount}");
_clientWebSocket = new ClientWebSocket(); // Create a new instance
await ConnectAsync(_currentUri);
if (IsConnected) break;
if (IsConnected)
{
break;
}
}
catch (Exception ex)
{
Log.Error($"Reconnect attempt failed: {ex.Message}");
Log.Error($"Reconnect attempt {retryCount + 1} failed: {ex.Message}");
}

retryCount++;
Expand All @@ -344,6 +348,7 @@ private async Task ReconnectAsync()
}



private async Task ReceiveLoopAsync(CancellationToken cancellationToken = default)
{
const int bufferSize = 4096; // Starting buffer size
Expand Down
4 changes: 2 additions & 2 deletions TEAMS2HA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<AssemblyVersion>1.1.0.225</AssemblyVersion>
<FileVersion>1.1.0.225</FileVersion>
<AssemblyVersion>1.1.0.228</AssemblyVersion>
<FileVersion>1.1.0.228</FileVersion>
<ApplicationIcon>Assets\Square150x150Logo.scale-200.ico</ApplicationIcon>
<Title>Teams2HA</Title>
<PackageIcon>Square150x150Logo.scale-200.png</PackageIcon>
Expand Down

0 comments on commit 16d9ad6

Please sign in to comment.