diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index 51b41d0fa..71ac1779d 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -8,25 +8,31 @@ exports.newDesktopApp = function newDesktopApp() { async function run() { /* - let socialGraphService = NT.projects.network.modules.socialGraph.newSocialGraph() - await socialGraphService.initialize() + Heree we will store our running objects: */ + DK.running = {} /* This is the Web Sockets client that interacts with the Superalgos Network. */ - DK.webSocketsClient = SA.projects.network.modules.webSocketsClient.newNetworkModulesWebSocketsClient() - await DK.webSocketsClient.initialize() + DK.running.socialGraph = DK.projects.socialTrading.modules.socialTrading.newSocialTradingModulesSocialGraph() + await DK.running.socialGraph.initialize() + + /* + This is the Web Sockets client that interacts with the Superalgos Network. + */ + DK.running.webSocketsClient = SA.projects.network.modules.webSocketsClient.newNetworkModulesWebSocketsClient() + await DK.running.webSocketsClient.initialize() /* These are the Network Interfaces by which the UI interacts with the Desktop App.*/ - - WEB_SOCKETS_INTERFACE = DK.projects.socialTrading.modules.webSocketsInterface.newDesktopModulesWebSocketsInterface() - WEB_SOCKETS_INTERFACE.initialize() - console.log('Web Sockets Interface ....................................... Listening at port ' + global.env.CLIENT_WEB_SOCKETS_INTERFACE_PORT) - - HTTP_INTERFACE = DK.projects.socialTrading.modules.httpInterface.newDesktopModulesHttpInterface() - HTTP_INTERFACE.initialize() + DK.running.webSocketsInterface = DK.projects.socialTrading.modules.webSocketsInterface.newDesktopModulesWebSocketsInterface() + DK.running.webSocketsInterface.initialize() + console.log('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('Http Interface .............................................. Listening at port ' + global.env.DESKTOP_HTTP_INTERFACE_PORT) return diff --git a/Desktop/UI/Globals.js b/Desktop/UI/Globals.js index 219cf4764..1890f2da3 100644 --- a/Desktop/UI/Globals.js +++ b/Desktop/UI/Globals.js @@ -2,6 +2,7 @@ let webApp let PROJECTS_SCHEMA +let ENVIRONMENT /* New Root object*/ let UI = { diff --git a/Desktop/UI/WebApp.js b/Desktop/UI/WebApp.js index 449764ac2..50e4fe172 100644 --- a/Desktop/UI/WebApp.js +++ b/Desktop/UI/WebApp.js @@ -14,7 +14,8 @@ function newWebApp() { function initialize() { try { setupRootObject() - //setupHomePage() + UI.projects.socialTrading.modules.webSocketsClient.initialize() + setupHomePage() } catch (err) { console.log('[ERROR] initialize -> err.stack = ' + err.stack) } @@ -85,7 +86,7 @@ function newWebApp() { queryMessage: JSON.stringify(queryMessage) } - await DK.webSocketsClient.sendMessage( + await UI.projects.socialTrading.modules.webSocketsClient.sendMessage( JSON.stringify(query) ) .then(showProfiles) @@ -97,56 +98,10 @@ function newWebApp() { for (let i = 0; i < profiles.length; i++) { let profile = profiles[i] - /* - Test Following Profiles. - */ - let eventMessage = { - eventId: SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId(), - eventType: SA.projects.socialTrading.globals.eventTypes.FOLLOW_USER_PROFILE, - emitterUserProfileId: DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID, - targetUserProfileId: profile.userProfileId - } - - let event = { - requestType: 'Event', - eventMessage: JSON.stringify(eventMessage) - } - - await DK.webSocketsClient.sendMessage( - JSON.stringify(event) - ) - .then(followAdded) - .catch(onError) - - function followAdded() { - console.log("User Profile " + profile.userProfileHandle + " followed.") - } + console.log(profile) } } - /* - Test Query User Profile Stats. - */ - queryMessage = { - queryType: SA.projects.socialTrading.globals.queryTypes.USER_PROFILE_STATS, - emitterUserProfileId: DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID, - targetUserProfileId: DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID - } - - query = { - requestType: 'Query', - queryMessage: JSON.stringify(queryMessage) - } - - await DK.webSocketsClient.sendMessage( - JSON.stringify(query) - ) - .then(showProfilesStats) - .catch(onError) - - function showProfilesStats(profile) { - console.log(profile) - } - + /* Error Handling */ diff --git a/Desktop/UI/WebAppPostLoader.js b/Desktop/UI/WebAppPostLoader.js index b22b7796d..a5f110bf6 100644 --- a/Desktop/UI/WebAppPostLoader.js +++ b/Desktop/UI/WebAppPostLoader.js @@ -10,7 +10,16 @@ function newWebAppPostLoader() { function start() { try { - setupProjectsSchema() + setupEnvironment() + + function setupEnvironment() { + httpRequest(undefined, 'Environment', onResponse) + + function onResponse(err, file) { + ENVIRONMENT = JSON.parse(file) + setupProjectsSchema() + } + } function setupProjectsSchema() { httpRequest(undefined, 'ProjectsSchema', onResponse) diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 6b3b9e278..6705b6a81 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1492,6 +1492,12 @@ "propertyName": "webAppInterface", "functionName": "newSocialTradingModulesWebAppInterface", "fileName": "WebAppInterface.js" + }, + { + "name": "Social Graph", + "propertyName": "socialGraph", + "functionName": "newSocialTradingModulesSocialGraph", + "fileName": "SocialGraph.js" } ], "utilities": [] diff --git a/Projects/Social-Trading/DK/modules/SocialGraph.js b/Projects/Social-Trading/DK/modules/SocialGraph.js new file mode 100644 index 000000000..d451f6179 --- /dev/null +++ b/Projects/Social-Trading/DK/modules/SocialGraph.js @@ -0,0 +1,25 @@ +exports.newSocialTradingModulesSocialGraph = function newSocialTradingModulesSocialGraph() { + /* + This module mantains in memory the personal social graph for + the user profile of the user of the Desktop App. A personal social + graph is very similar to the one mantained at a Netwrok Node, + the mainn difference is that it only includes information relevant + to this particular user, and not for al the users in the system + as in the Network Node. + */ + let thisObject = { + messageReceived: messageReceived, + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + + } + + function initialize() { + + } +} \ No newline at end of file diff --git a/Projects/Social-Trading/DK/modules/WebAppInterface.js b/Projects/Social-Trading/DK/modules/WebAppInterface.js index 228b1ec80..10fb0d796 100644 --- a/Projects/Social-Trading/DK/modules/WebAppInterface.js +++ b/Projects/Social-Trading/DK/modules/WebAppInterface.js @@ -1,7 +1,10 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModulesWebAppInterface() { - + /* + This module handles the incomming messages from the Web App. + At it's current iteration, it will jusr forward those messages + to the Network Node it is connected to. + */ let thisObject = { - sendToWebApp: undefined, messageReceived: messageReceived, initialize: initialize, finalize: finalize @@ -17,11 +20,8 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule } - function messageReceived(messageHeader) { - let response = { - result: 'Ok', - message: 'Hello !' - } - return + async function messageReceived(messageHeader) { + let response = await DK.running.webSocketsClient.sendMessage(messageHeader) + return 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 3714e01ee..0aa2f381b 100644 --- a/Projects/Social-Trading/DK/modules/WebSocketsInterface.js +++ b/Projects/Social-Trading/DK/modules/WebSocketsInterface.js @@ -1,6 +1,10 @@ exports.newDesktopModulesWebSocketsInterface = function newDesktopModulesWebSocketsInterface() { - + /* + This module handles the websockets communication between the + Desktop App's Client and the Destop App's Web App. + */ let thisObject = { + sendToWebApp: sendToWebApp, initialize: initialize, finalize: finalize } @@ -27,7 +31,6 @@ exports.newDesktopModulesWebSocketsInterface = function newDesktopModulesWebSock function setUpWebSocketServer() { try { socketServer.on('connection', onConnectionOpened) - webAppInterface.sendToWebApp = sendToWebApp function onConnectionOpened(socket) @@ -73,12 +76,12 @@ exports.newDesktopModulesWebSocketsInterface = function newDesktopModulesWebSock webApp = undefined } - function sendToWebApp(message) { - webApp.socket.send(JSON.stringify(message)) - } - } catch (err) { console.log('[ERROR] Web Sockets Interface -> setUpWebSocketServer -> err.stack = ' + err.stack) } + + function sendToWebApp(message) { + webApp.socket.send(JSON.stringify(message)) + } } } \ No newline at end of file diff --git a/Projects/Social-Trading/DK/modules/httpInterface.js b/Projects/Social-Trading/DK/modules/httpInterface.js index 644886080..1959bf289 100644 --- a/Projects/Social-Trading/DK/modules/httpInterface.js +++ b/Projects/Social-Trading/DK/modules/httpInterface.js @@ -35,6 +35,11 @@ exports.newDesktopModulesHttpInterface = function newDesktopModulesHttpInterface let endpointOrFile = requestPath[1] switch (endpointOrFile) { + case 'Environment': + { + SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(global.env), httpResponse) + } + break case 'ProjectsSchema': { let path = global.env.PATH_TO_PROJECTS + '/' + 'ProjectsSchema.json'