Skip to content

Commit

Permalink
Fix Eventlistener not restarting
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-dmxc committed Mar 27, 2021
1 parent e84fdc6 commit d6fecda
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions API/Communication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,13 +634,12 @@ public static void StopEventListener()
eventCleanLoop = null;
}

public static async Task<bool> StartEventListener(string ip, string port, string auth_token)
public static async Task StartEventListener(string ip, string port, string auth_token)
{
string address = $"http://{ip}:{port}/api/v1/{auth_token}/events?id=1,2,3,4";
WebClient wc = new WebClient();
wc.Headers.Add("TouchEventsPort", _touchEventsPort.ToString());
wc.OpenReadAsync(new Uri(address));
bool restart = false;
bool isListening = true;
wc.OpenReadCompleted += (sender, args) =>
{
Expand All @@ -660,9 +659,7 @@ public static async Task<bool> StartEventListener(string ip, string port, string
}
catch (Exception e) when (e is IOException || e is WebException)//Timeout! Restart Listener without Logging
{
restart = true;
isListening = false;
return;
NanoleafPlugin.Log.Debug("Restarting EventListener because of:" + Environment.NewLine, e);
}
catch (Exception e) when (e is TargetInvocationException)
{
Expand All @@ -683,7 +680,6 @@ public static async Task<bool> StartEventListener(string ip, string port, string
};
while (isListening)
await Task.Delay(10);
return restart;
}

private static async Task FireEvent(string ip, string eventData)
Expand Down

0 comments on commit d6fecda

Please sign in to comment.