Added ability to count connected clients for future use. Accessed via TumblerPhaseBroadcaster.ConnectedClientCount()
MODIFY
HiddenWallet.ChaumianTumbler/TumblerPhaseBroadcaster.cs
HiddenWallet.ChaumianTumbler/TumblerPhaseBroadcaster.cs
using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json;
using System;
+using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -12,12 +13,12 @@ namespace HiddenWallet.ChaumianTumbler
{
private readonly static Lazy<TumblerPhaseBroadcaster> _instance = new Lazy<TumblerPhaseBroadcaster>(() => new TumblerPhaseBroadcaster());
- private IHubContext<TumblerHub> _context; //The context of the hub - needed in order for the tumbler to act on MVC submitted data and call the hub to issue updates
+ private readonly ConcurrentDictionary<string, string> _connectedClients = new ConcurrentDictionary<string, string>();
+
+ private IHubContext<TumblerHub> _context;
private TumblerPhaseBroadcaster()
- {
- // Put any code to initliase collections etc. here.
- }
+ { }
public static TumblerPhaseBroadcaster Instance => _instance.Value;
@@ -29,6 +30,12 @@ namespace HiddenWallet.ChaumianTumbler
}
}
+ public void AddConnectedClient(string id) => _connectedClients.TryAdd(id, id);
+
+ public void RemoveConnectedClient(string id) => _connectedClients.Remove(id, out string value);
+
+ public int ConnectedClientCount() => _connectedClients.Count();
+
public void Broadcast(PhaseChangeBroadcast broadcast)
{
IClientProxy proxy = _context.Clients.All;

Added ability to count connected clients for future use. Accessed via TumblerPhaseBroadcaster.ConnectedClientCount()