From 2170e2db5ffd64cfbc37ee3ef5d8ff060ce21d02 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 25 Dec 2024 17:08:05 +0100 Subject: [PATCH] Check for adding existing connections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Added a check for existing Websocket connections, related to the issue #112 --- Services/GotifySocketService.cs | 6 +++++- iGotify Notification Assist.csproj | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Services/GotifySocketService.cs b/Services/GotifySocketService.cs index fc86ab1..4532cba 100644 --- a/Services/GotifySocketService.cs +++ b/Services/GotifySocketService.cs @@ -71,7 +71,11 @@ private static void StartWsConn(string gotifyServerUrl, string clientToken) if (_websocketThreads == null) _websocketThreads = new Dictionary(); - _websocketThreads.Add(clientToken, wsc); + _websocketThreads.TryGetValue(clientToken, out var storedWebSockClient); + if (storedWebSockClient == null) + _websocketThreads.Add(clientToken, wsc); + else + Console.WriteLine($"Client: {clientToken} already connected! Skipping..."); Thread.Sleep(Timeout.Infinite); } diff --git a/iGotify Notification Assist.csproj b/iGotify Notification Assist.csproj index 1dc1828..84a59f4 100644 --- a/iGotify Notification Assist.csproj +++ b/iGotify Notification Assist.csproj @@ -19,7 +19,7 @@ - +