Skip to content

Commit

Permalink
TwitchChatVotingProxy/OverlayServer: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Feb 7, 2024
1 parent 2f37381 commit 33d55f2
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions TwitchChatVotingProxy/OverlayServer/OverlayServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace TwitchChatVotingProxy.OverlayServer
class OverlayServer : IOverlayServer
{
private readonly OverlayServerConfig config;
private readonly List<Fleck.IWebSocketConnection> connections = new();
private readonly List<IWebSocketConnection> connections = new();
private readonly ILogger logger = Log.Logger.ForContext<OverlayServer>();

public OverlayServer(OverlayServerConfig config)
Expand All @@ -17,7 +17,7 @@ public OverlayServer(OverlayServerConfig config)

try
{
var WSS = new Fleck.WebSocketServer($"ws://0.0.0.0:{config.Port}");
var WSS = new WebSocketServer($"ws://0.0.0.0:{config.Port}");
// Set the websocket listeners
WSS.Start(connection =>
{
Expand All @@ -27,7 +27,7 @@ public OverlayServer(OverlayServerConfig config)
}
catch (Exception e)
{
logger.Fatal(e, "failed so start websocket server");
logger.Fatal(e, "Failed so start websocket server");
}
}

Expand Down Expand Up @@ -57,8 +57,14 @@ private void Broadcast(string message)
connections.ForEach(connection =>
{
// If the connection is not available for some reason, we just close it
if (!connection.IsAvailable) connection.Close();
else connection.Send(message);
if (!connection.IsAvailable)
{
connection.Close();
}
else
{
connection.Send(message);
}
});
}
/// <summary>
Expand All @@ -69,12 +75,12 @@ private void OnWSConnectionClose(IWebSocketConnection connection)
{
try
{
logger.Information($"websocket client disconnected {connection.ConnectionInfo.ClientIpAddress}");
logger.Information($"Websocket client disconnected {connection.ConnectionInfo.ClientIpAddress}");
connections.Remove(connection);
}
catch (Exception e)
{
logger.Error(e, "error occurred as client disconnected");
logger.Error(e, "Error occurred as client disconnected");
}
}
/// <summary>
Expand All @@ -85,12 +91,12 @@ private void OnWsConnectionOpen(IWebSocketConnection connection)
{
try
{
logger.Information($"new websocket client {connection.ConnectionInfo.ClientIpAddress}");
logger.Information($"New websocket client {connection.ConnectionInfo.ClientIpAddress}");
connections.Add(connection);
}
catch (Exception e)
{
logger.Error(e, "error occurred as client connected");
logger.Error(e, "Error occurred as client connected");
}
}
/// <summary>
Expand All @@ -113,7 +119,7 @@ private void Request(string request, List<IVoteOption> voteOptions)
}
else
{
logger.Error($"could not find voting mode {config.VotingMode} in dictionary");
logger.Error($"Could not find voting mode {config.VotingMode} in dictionary");
msg.VotingMode = "UNKNOWN_VOTING_MODE";
}
// Count total votes
Expand Down

0 comments on commit 33d55f2

Please sign in to comment.