diff --git a/core/api.js b/core/api.js index 2da73e104..1523c5107 100644 --- a/core/api.js +++ b/core/api.js @@ -29,8 +29,6 @@ module.exports = (function () { parseDate(date, format), storeData: (mpath, d, e) => storeData(mpath, d, e), parseData: (d) => parseData(d), - eventAndContent: (sendEvent, objectJson) => - eventAndContent(sendEvent, objectJson), sendEventWithContent: (sendEvent, objectContent, io, socket) => sendEventWithContent(sendEvent, objectContent, io, socket), getNetworkInfos: () => getNetworkInfos(), @@ -143,52 +141,30 @@ module.exports = (function () { }); } - function eventAndContent(sendEvent, objectJson) { - var eventContentJSON = { + function sendEventWithContent(sendEvent, objectContent, io, socket) { + let eventAndContentJson = { socketevent: sendEvent, - content: objectJson, + content: objectContent, }; - return eventContentJSON; - } - function sendEventWithContent(sendEvent, objectContent, io, socket) { - let eventAndContentJson = eventAndContent(sendEvent, objectContent); - let eventAndContentJson_string = JSON.stringify( - eventAndContentJson.socketevent, - null, - 4 - ); - if (socket) { + dev.logpackets({ + str: `sendEventWithContent ${ + socket && socket.id ? `for user ` + socket.id : "for all users" + } with type ${eventAndContentJson.socketevent}`, + obj: eventAndContentJson.content, + }); + + if (socket) // content sent only to one user - dev.logpackets( - `sendEventWithContent for user ${socket.id} = ${eventAndContentJson_string}` - ); socket.emit( eventAndContentJson["socketevent"], eventAndContentJson["content"] ); - } else { - // content broadcasted to all connected users - dev.logpackets( - `sendEventWithContent for all users = ${eventAndContentJson_string}` - ); + else io.sockets.emit( eventAndContentJson["socketevent"], eventAndContentJson["content"] ); - } - // dev.logpackets( - // `sendEventWithContent — sending packet with content = ${JSON.stringify( - // eventAndContentJson['content'], - // null, - // 4 - // )}` - // ); - dev.logpackets( - `eventAndContentJson — sending packet with string length = ${ - JSON.stringify(eventAndContentJson["content"]).length - }` - ); } // from http://stackoverflow.com/a/8440736 diff --git a/core/dev-log.js b/core/dev-log.js index edb39af6b..584a4f3fd 100644 --- a/core/dev-log.js +++ b/core/dev-log.js @@ -28,8 +28,7 @@ module.exports = dev = (function () { console.log("Debug mode is Enabled"); console.log("---"); dev.logfunction("(log) magenta is for functions"); - dev.logpackets("(log) green is for packets"); - dev.logpackets("(log) green is for packets"); + dev.logpackets({ str: "(log) green is for packets" }); if (isVerboseMode) { dev.logverbose("(dev and verbose) gray for regular parsing data"); } @@ -62,17 +61,19 @@ module.exports = dev = (function () { _sendToConsole(logArgs, gutil.colors.gray); } } - function logpackets() { + function logpackets({ str, obj }) { if (!logToFile && !isDebugMode) return; // green - var args = Array.prototype.slice.call(arguments); - var logArgs = "* ".concat(args); + let log_string = "* "; + + if (str) log_string += str; + if (obj) log_string += JSON.stringify(obj); if (logToFile) { - _sendToLogFile(logArgs); + _sendToLogFile(log_string); } if (isDebugMode) { - _sendToConsole(logArgs, gutil.colors.green); + _sendToConsole(log_string, gutil.colors.green); } } function logfunction() { diff --git a/core/sockets.js b/core/sockets.js index 909472270..4ac68dc73 100644 --- a/core/sockets.js +++ b/core/sockets.js @@ -50,6 +50,12 @@ module.exports = (function () { } }).on("connection", function (socket) { dev.log(`RECEIVED CONNECTION FROM SOCKET.id: ${socket.id}`); + dev.log( + `Clients connected currently : ${ + Object.keys(io.sockets.connected).length + }` + ); + socket._data = {}; var onevent = socket.onevent; @@ -1133,6 +1139,12 @@ module.exports = (function () { function onClientDisconnect(socket) { sendClients(); + + dev.log( + `Clients connected currently : ${ + Object.keys(io.sockets.connected).length + }` + ); } async function onLoadJournal(socket) {