From 05821c765631e9529c9550d13c2582d469f6fe3a Mon Sep 17 00:00:00 2001 From: Matthew Cotton Date: Wed, 29 Nov 2023 12:02:02 +1100 Subject: [PATCH] Fixing small issue where if a streamer disconnected before identifying the signalling server would create a legacy name that would be left behind. Fixing some logging calls that would not properly be handled by the logging system. --- SignallingWebServer/cirrus.js | 15 +++++++++-- SignallingWebServer/modules/logging.js | 36 +++++++++++++++++--------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/SignallingWebServer/cirrus.js b/SignallingWebServer/cirrus.js index 48477918..9d6a0c1a 100644 --- a/SignallingWebServer/cirrus.js +++ b/SignallingWebServer/cirrus.js @@ -550,6 +550,10 @@ function registerStreamer(id, streamer) { } function onStreamerDisconnected(streamer) { + if (!!streamer.idTimer) { + clearTimeout(streamer.idTimer); + } + if (!streamer.id || !streamers.has(streamer.id)) { return; } @@ -665,7 +669,10 @@ streamerServer.on('connection', function (ws, req) { } }); - ws.send(JSON.stringify(clientConfig)); + const configStr = JSON.stringify(clientConfig); + logOutgoing(streamer.id, configStr) + ws.send(configStr); + requestStreamerId(streamer); }); @@ -960,7 +967,11 @@ playerServer.on('connection', function (ws, req) { sendPlayerConnectedToFrontend(); sendPlayerConnectedToMatchmaker(); - player.ws.send(JSON.stringify(clientConfig)); + + const configStr = JSON.stringify(clientConfig); + logOutgoing(player.id, configStr) + player.ws.send(configStr); + sendPlayersCount(); }); diff --git a/SignallingWebServer/modules/logging.js b/SignallingWebServer/modules/logging.js index 3c750b4f..b2d85064 100644 --- a/SignallingWebServer/modules/logging.js +++ b/SignallingWebServer/modules/logging.js @@ -7,18 +7,6 @@ var loggers=[]; var logFunctions=[]; var logColorFunctions=[]; -console.log = function(msg, ...args) { - logFunctions.forEach((logFunction) => { - logFunction(msg, ...args); - }); -} - -console.logColor = function(color, msg, ...args) { - logColorFunctions.forEach((logColorFunction) => { - logColorFunction(color, msg, ...args); - }); -} - const AllAttributesOff = '\x1b[0m'; const BoldOn = '\x1b[1m'; const Black = '\x1b[30m'; @@ -31,6 +19,30 @@ const Cyan = '\x1b[36m'; const White = '\x1b[37m'; const Orange = '\x1b[38;5;215m'; +console.log = function(msg, ...args) { + logFunctions.forEach((logFunction) => { + logFunction(msg, ...args); + }); +} + +console.warn = function(msg, ...args) { + logColorFunctions.forEach((logColorFunction) => { + logColorFunction(Yellow, msg, ...args); + }); +} + +console.error = function(msg, ...args) { + logColorFunctions.forEach((logColorFunction) => { + logColorFunction(Red, msg, ...args); + }); +} + +console.logColor = function(color, msg, ...args) { + logColorFunctions.forEach((logColorFunction) => { + logColorFunction(color, msg, ...args); + }); +} + /** * Pad the start of the given number with zeros so it takes up the number of digits. * e.g. zeroPad(5, 3) = '005' and zeroPad(23, 2) = '23'.