diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index 2115de147..66838c3fe 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -23,18 +23,18 @@ exports.newDesktopApp = function newDesktopApp() { */ DK.running.webSocketsClient = SA.projects.network.modules.webSocketsClient.newNetworkModulesWebSocketsClient() await DK.running.webSocketsClient.initialize() - console.log('Desktop App Client Connected to Network Node via Web Sockets ................... Connected to port ' + global.env.NETWORK_WEB_SOCKETS_INTERFACE_PORT) + console.log('Desktop Client Connected to Network Node via Web Sockets ................... Connected to port ' + global.env.NETWORK_WEB_SOCKETS_INTERFACE_PORT) /* These are the Network Interfaces by which the UI interacts with the Desktop App.*/ DK.running.webSocketsInterface = DK.projects.socialTrading.modules.webSocketsInterface.newDesktopModulesWebSocketsInterface() DK.running.webSocketsInterface.initialize() - console.log('Desktop App Client Web Sockets Interface ....................................... Listening at port ' + global.env.CLIENT_WEB_SOCKETS_INTERFACE_PORT) + console.log('Desktop Client Web Sockets Interface ....................................... Listening at port ' + global.env.CLIENT_WEB_SOCKETS_INTERFACE_PORT) DK.running.httpInterface = DK.projects.socialTrading.modules.httpInterface.newDesktopModulesHttpInterface() DK.running.httpInterface.initialize() - console.log('Desktop App Client Http Interface .............................................. Listening at port ' + global.env.DESKTOP_HTTP_INTERFACE_PORT) + console.log('Desktop Client Http Interface .............................................. Listening at port ' + global.env.DESKTOP_HTTP_INTERFACE_PORT) return diff --git a/Desktop/UI/WebApp.js b/Desktop/UI/WebApp.js index 0abdd29eb..482204139 100644 --- a/Desktop/UI/WebApp.js +++ b/Desktop/UI/WebApp.js @@ -11,11 +11,11 @@ function newWebApp() { } - function initialize() { + async function initialize() { try { setupRootObject(UI, 'UI') setupRootObject(SA, 'SA') - UI.projects.socialTrading.modules.webSocketsClient.initialize() + await UI.projects.socialTrading.modules.webSocketsClient.initialize() setupHomePage() } catch (err) { console.log('[ERROR] initialize -> err.stack = ' + err.stack) @@ -101,7 +101,7 @@ function newWebApp() { */ queryMessage = { queryType: SA.projects.socialTrading.globals.queryTypes.USER_PROFILES, - emitterUserProfileId: undefined, //DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID, + emitterUserProfileId: undefined, initialIndex: 'Last', amountRequested: 10, direction: 'Past' diff --git a/Projects/Social-Trading/DK/modules/WebAppInterface.js b/Projects/Social-Trading/DK/modules/WebAppInterface.js index 10fb0d796..ef3a6bd6f 100644 --- a/Projects/Social-Trading/DK/modules/WebAppInterface.js +++ b/Projects/Social-Trading/DK/modules/WebAppInterface.js @@ -20,8 +20,68 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule } - async function messageReceived(messageHeader) { - let response = await DK.running.webSocketsClient.sendMessage(messageHeader) - return response + async function messageReceived(message) { + let messageHeader + try { + messageHeader = JSON.parse(message) + } catch (err) { + let response = { + result: 'Error', + message: 'messageHeader Not Coorrect JSON Format.' + } + return JSON.stringify(response) + } + + switch (messageHeader.requestType) { + case 'Query': { + let queryMessage + try { + queryMessage = JSON.parse(messageHeader.queryMessage) + } catch (err) { + let response = { + result: 'Error', + message: 'queryMessage Not Coorrect JSON Format.' + } + return JSON.stringify(response) + } + queryMessage.emitterUserProfileId = DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID + messageHeader.queryMessage = JSON.stringify(queryMessage) + + let response = { + result: 'Ok', + message: 'Web App Interface Query Processed.', + data: await DK.running.webSocketsClient.sendMessage(JSON.stringify(messageHeader)) + } + return response + } + case 'Event': { + let eventMessage + try { + eventMessage = JSON.parse(messageHeader.eventMessage) + } catch (err) { + let response = { + result: 'Error', + message: 'eventMessage Not Coorrect JSON Format.' + } + return JSON.stringify(response) + } + eventMessage.emitterUserProfileId = DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID + messageHeader.eventMessage = JSON.stringify(eventMessage) + + let response = { + result: 'Ok', + message: 'Web App Interface Event Processed.', + data: await DK.running.webSocketsClient.sendMessage(JSON.stringify(messageHeader)) + } + return response + } + default: { + let response = { + result: 'Error', + message: 'requestType Not Supported.' + } + return JSON.stringify(response) + } + } } } \ No newline at end of file diff --git a/Projects/Social-Trading/DK/modules/WebSocketsInterface.js b/Projects/Social-Trading/DK/modules/WebSocketsInterface.js index dd2cd723c..89b577960 100644 --- a/Projects/Social-Trading/DK/modules/WebSocketsInterface.js +++ b/Projects/Social-Trading/DK/modules/WebSocketsInterface.js @@ -45,6 +45,7 @@ exports.newDesktopModulesWebSocketsInterface = function newDesktopModulesWebSock webApp = { socket: socket } + console.log('Desktop Web App Connected to Web Sockets Interface ......................... Connected to port ' + global.env.CLIENT_WEB_SOCKETS_INTERFACE_PORT) webApp.socket.on('close', onConnectionClosed) webApp.socket.on('message', onMenssage) @@ -74,6 +75,7 @@ exports.newDesktopModulesWebSocketsInterface = function newDesktopModulesWebSock function onConnectionClosed() { webApp = undefined + console.log('Desktop Web App Discoonnected from Web Sockets Interface ................... Disonnected from port ' + global.env.CLIENT_WEB_SOCKETS_INTERFACE_PORT) } } catch (err) {