From f441406dd5bce89309eecc34ba3333ad5a44499f Mon Sep 17 00:00:00 2001 From: AlphaX-Projects <77661270+AlphaX-Projects@users.noreply.github.com> Date: Wed, 26 Jul 2023 20:10:41 +0200 Subject: [PATCH] Remove log spam --- plugins/plugins/core/streams/onNewBlock.js | 123 +++------------------ plugins/plugins/core/streams/streams.js | 20 ++-- 2 files changed, 25 insertions(+), 118 deletions(-) diff --git a/plugins/plugins/core/streams/onNewBlock.js b/plugins/plugins/core/streams/onNewBlock.js index f02cc38b..0f9bfc38 100644 --- a/plugins/plugins/core/streams/onNewBlock.js +++ b/plugins/plugins/core/streams/onNewBlock.js @@ -7,20 +7,16 @@ let closeGracefully = false let isCalled = false let retryOnClose = false let blockFirstCall = true - let nodeStatusSocketObject let nodeStatusSocketTimeout let nodeStatusSocketcloseGracefully = false let nodeStatusCount = 0 let nodeStatusRetryOnClose = false let nodeStateCall = false - let isLoggedIn = false - let oldAccountInfo parentEpml.subscribe('logged_in', loggedIn => { - if (loggedIn === 'true') { isLoggedIn = true } else { @@ -29,35 +25,28 @@ parentEpml.subscribe('logged_in', loggedIn => { }) const setAccountInfo = async (addr) => { - const names = await parentEpml.request('apiCall', { url: `/names/address/${addr}` }) const addressInfo = await parentEpml.request('apiCall', { url: `/addresses/${addr}` }) - let accountInfo = { names: names, addressInfo: addressInfo } - if (window.parent._.isEqual(oldAccountInfo, accountInfo) === true) { - return } else { - parentEpml.request('setAccountInfo', accountInfo) oldAccountInfo = accountInfo } } const doNodeInfo = async () => { - const nodeInfo = await parentEpml.request('apiCall', { url: '/admin/info' }) - parentEpml.request('updateNodeInfo', nodeInfo) } @@ -65,71 +54,57 @@ let initStateCount = 0 let oldState const closeSockets = () => { - - socketObject.close(); + socketObject.close() closeGracefully = true - - nodeStatusSocketObject.close(); + nodeStatusSocketObject.close() nodeStatusSocketcloseGracefully = true } export const startConfigWatcher = () => { - parentEpml.ready().then(() => { parentEpml.subscribe('node_config', c => { - if (initStateCount === 0) { let _oldState = JSON.parse(c) oldState = { node: _oldState.node, knownNodes: _oldState.knownNodes } initStateCount = initStateCount + 1 - nodeStateCall = true isCalled = true - socketObject !== undefined ? closeSockets() : undefined; - nodeStatusSocketObject !== undefined ? closeSockets() : undefined; + socketObject !== undefined ? closeSockets() : undefined + nodeStatusSocketObject !== undefined ? closeSockets() : undefined initNodeStatusCall(oldState) pingactiveBlockSocket() - // Call doNodeInfo doNodeInfo() } - - let _newState = JSON.parse(c); + let _newState = JSON.parse(c) let newState = { node: _newState.node, knownNodes: _newState.knownNodes } - if (window.parent._.isEqual(oldState, newState) === true) { return } else { oldState = newState nodeStateCall = true isCalled = true - socketObject !== undefined ? closeSockets() : undefined; - nodeStatusSocketObject !== undefined ? closeSockets() : undefined; + socketObject !== undefined ? closeSockets() : undefined + nodeStatusSocketObject !== undefined ? closeSockets() : undefined initNodeStatusCall(newState) pingactiveBlockSocket() - // Call doNodeInfo doNodeInfo() } }) }) - parentEpml.imReady() } const processBlock = (blockObject) => { - parentEpml.request('updateBlockInfo', blockObject) } const doNodeStatus = async (nodeStatusObject) => { - parentEpml.request('updateNodeStatus', nodeStatusObject) } - const initNodeStatusCall = (nodeConfig) => { - if (nodeConfig.node == 0) { pingNodeStatusSocket() } else if (nodeConfig.node == 1) { @@ -143,193 +118,131 @@ const initNodeStatusCall = (nodeConfig) => { } const initBlockSocket = () => { - let myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node] let nodeUrl = myNode.domain + ":" + myNode.port - let activeBlockSocketLink - if (window.parent.location.protocol === "https:") { - - activeBlockSocketLink = `wss://${nodeUrl}/websockets/blocks`; + activeBlockSocketLink = `wss://${nodeUrl}/websockets/blocks` } else { - - activeBlockSocketLink = `ws://${nodeUrl}/websockets/blocks`; + activeBlockSocketLink = `ws://${nodeUrl}/websockets/blocks` } - - const activeBlockSocket = new WebSocket(activeBlockSocketLink); - + const activeBlockSocket = new WebSocket(activeBlockSocketLink) // Open Connection activeBlockSocket.onopen = (e) => { - - console.log(`[SOCKET-BLOCKS]: Connected.`); closeGracefully = false socketObject = activeBlockSocket - initial = initial + 1 } - // Message Event activeBlockSocket.onmessage = (e) => { - - processBlock(JSON.parse(e.data)); - + processBlock(JSON.parse(e.data)) if (isLoggedIn) { - // Call Set Account Info... setAccountInfo(window.parent.reduxStore.getState().app.selectedAddress.address) } } - // Closed Event activeBlockSocket.onclose = () => { - - console.log(`[SOCKET-BLOCKS]: CLOSED`); - - processBlock({}); + processBlock({}) blockFirstCall = true clearInterval(activeBlockSocketTimeout) if (closeGracefully === false && initial <= 52) { - if (initial <= 52) { - retryOnClose = true setTimeout(pingactiveBlockSocket, 10000) initial = initial + 1 } else { - // ... Stop retrying... retryOnClose = false } } } - // Error Event activeBlockSocket.onerror = (e) => { - - console.log(`[SOCKET-BLOCKS]: ${e.type}`); blockFirstCall = true - processBlock({}); + processBlock({}) } - if (blockFirstCall) { - parentEpml.request('apiCall', { url: '/blocks/last' }).then(res => { - processBlock(res) blockFirstCall = false }) } } - const pingactiveBlockSocket = () => { - if (isCalled) { - isCalled = false - initBlockSocket() activeBlockSocketTimeout = setTimeout(pingactiveBlockSocket, 295000) } else if (retryOnClose) { - retryOnClose = false clearTimeout(activeBlockSocketTimeout) initBlockSocket() isCalled = true activeBlockSocketTimeout = setTimeout(pingactiveBlockSocket, 295000) } else { - socketObject.send("non-integer ping") activeBlockSocketTimeout = setTimeout(pingactiveBlockSocket, 295000) } } - const initNodeStatusSocket = () => { - let myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node] let nodeUrl = myNode.domain + ":" + myNode.port - let activeNodeStatusSocketLink - if (window.parent.location.protocol === "https:") { - - activeNodeStatusSocketLink = `wss://${nodeUrl}/websockets/admin/status`; + activeNodeStatusSocketLink = `wss://${nodeUrl}/websockets/admin/status` } else { - - activeNodeStatusSocketLink = `ws://${nodeUrl}/websockets/admin/status`; + activeNodeStatusSocketLink = `ws://${nodeUrl}/websockets/admin/status` } - - const activeNodeStatusSocket = new WebSocket(activeNodeStatusSocketLink); - + const activeNodeStatusSocket = new WebSocket(activeNodeStatusSocketLink) // Open Connection activeNodeStatusSocket.onopen = (e) => { - - console.log(`[SOCKET-NODE-STATUS]: Connected.`); nodeStatusSocketcloseGracefully = false nodeStatusSocketObject = activeNodeStatusSocket - nodeStatusCount = nodeStatusCount + 1 } - // Message Event activeNodeStatusSocket.onmessage = (e) => { - doNodeStatus(JSON.parse(e.data)) } - // Closed Event activeNodeStatusSocket.onclose = () => { - - console.log(`[SOCKET-NODE-STATUS]: CLOSED`); - - doNodeStatus({}); + doNodeStatus({}) clearInterval(nodeStatusSocketTimeout) - if (nodeStatusSocketcloseGracefully === false && nodeStatusCount <= 52) { - if (nodeStatusCount <= 52) { - nodeStatusRetryOnClose = true setTimeout(pingNodeStatusSocket, 10000) nodeStatusCount = nodeStatusCount + 1 } else { - // ... Stop retrying... nodeStatusRetryOnClose = false } } } - // Error Event activeNodeStatusSocket.onerror = (e) => { - - console.log(`[SOCKET-NODE-STATUS]: ${e.type}`); - doNodeStatus({}); + doNodeStatus({}) } } - const pingNodeStatusSocket = () => { - if (nodeStateCall) { - clearTimeout(nodeStatusSocketTimeout) initNodeStatusSocket() nodeStateCall = false nodeStatusSocketTimeout = setTimeout(pingNodeStatusSocket, 295000) } else if (nodeStatusRetryOnClose) { - nodeStatusRetryOnClose = false clearTimeout(nodeStatusSocketTimeout) initNodeStatusSocket() nodeStatusSocketTimeout = setTimeout(pingNodeStatusSocket, 295000) } else { - nodeStatusSocketObject.send("non-integer ping") nodeStatusSocketTimeout = setTimeout(pingNodeStatusSocket, 295000) } diff --git a/plugins/plugins/core/streams/streams.js b/plugins/plugins/core/streams/streams.js index 563df338..809bd53d 100644 --- a/plugins/plugins/core/streams/streams.js +++ b/plugins/plugins/core/streams/streams.js @@ -45,7 +45,7 @@ const sortActiveChat = (activeChatObject, localChatHeads) => { let results = newActiveChats.filter(newChat => { let value = oldActiveChats.some(oldChat => newChat.timestamp === oldChat.timestamp) return !value - }); + }) results.forEach(chat => { @@ -103,8 +103,6 @@ const chatHeadWatcher = (activeChats) => { } } catch (e) { - console.error(e) - } } @@ -128,13 +126,13 @@ parentEpml.subscribe('logged_in', async isLoggedIn => { if (window.parent.location.protocol === "https:") { - activeChatSocketLink = `wss://${nodeUrl}/websockets/chat/active/${window.parent.reduxStore.getState().app.selectedAddress.address}?encoding=BASE64`; + activeChatSocketLink = `wss://${nodeUrl}/websockets/chat/active/${window.parent.reduxStore.getState().app.selectedAddress.address}?encoding=BASE64` } else { - activeChatSocketLink = `ws://${nodeUrl}/websockets/chat/active/${window.parent.reduxStore.getState().app.selectedAddress.address}?encoding=BASE64`; + activeChatSocketLink = `ws://${nodeUrl}/websockets/chat/active/${window.parent.reduxStore.getState().app.selectedAddress.address}?encoding=BASE64` } - const activeChatSocket = new WebSocket(activeChatSocketLink); + const activeChatSocket = new WebSocket(activeChatSocketLink) // Open Connection activeChatSocket.onopen = () => { @@ -147,16 +145,14 @@ parentEpml.subscribe('logged_in', async isLoggedIn => { // Message Event activeChatSocket.onmessage = (e) => { if (e.data === 'pong') { - clearTimeout(timeoutId); + clearTimeout(timeoutId) activeChatSocketTimeout = setTimeout(pingActiveChatSocket, 45000) return } try { chatHeadWatcher(JSON.parse(e.data)) } catch (error) { - } - } // Closed Event @@ -171,8 +167,6 @@ parentEpml.subscribe('logged_in', async isLoggedIn => { // Error Event activeChatSocket.onerror = (e) => { - - console.log(`[SOCKET]: ${e.type}`); } } @@ -197,9 +191,9 @@ parentEpml.subscribe('logged_in', async isLoggedIn => { socketObject.send('ping') timeoutId = setTimeout(() => { - socketObject.close(); + socketObject.close() clearTimeout(activeChatSocketTimeout) - }, 5000); + }, 5000) } } else {