diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index 300baff29..51b41d0fa 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -19,16 +19,13 @@ exports.newDesktopApp = function newDesktopApp() { await DK.webSocketsClient.initialize() /* These are the Network Interfaces by which the UI interacts with the Desktop App.*/ - //let WEB_SOCKETS_INTERFACE = require('./Client/webSocketsInterface.js') - let HTTP_INTERFACE = require('./Client/httpInterface.js') - - /* - WEB_SOCKETS_INTERFACE = WEB_SOCKETS_INTERFACE.newWebSocketsInterface() + + 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 = HTTP_INTERFACE.newHttpInterface() + HTTP_INTERFACE = DK.projects.socialTrading.modules.httpInterface.newDesktopModulesHttpInterface() HTTP_INTERFACE.initialize() console.log('Http Interface .............................................. Listening at port ' + global.env.DESKTOP_HTTP_INTERFACE_PORT) diff --git a/EnvironmentForDebug.js b/EnvironmentForDebug.js index 932ed022b..01b010fc1 100644 --- a/EnvironmentForDebug.js +++ b/EnvironmentForDebug.js @@ -4,6 +4,7 @@ exports.newEnvironment = function () { WEB_SERVER_URL: 'localhost', CLIENT_WEB_SOCKETS_INTERFACE_PORT: 18041, NETWORK_WEB_SOCKETS_INTERFACE_PORT: 18042, + DESKTOP_WEB_SOCKETS_INTERFACE_PORT: 18043, CLIENT_HTTP_INTERFACE_PORT: 34248, DESKTOP_HTTP_INTERFACE_PORT: 34249, PATH_TO_TASK_SERVER: './TaskServer', diff --git a/MultiProject.js b/MultiProject.js index 47506b2cc..bc4f3035d 100644 --- a/MultiProject.js +++ b/MultiProject.js @@ -65,7 +65,7 @@ exports.newMultiProject = function () { } /* - From here we will require and get the modules, but without instantiation thisObject. + From here we will require and get the modules, but without instantiating thisObject. */ /* Set up Modules for this Project */ diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 2b8ea0bb8..395ff21b4 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1471,6 +1471,30 @@ "fileName": "EventTypes.js" } ] + }, + "DK": { + "globals": [], + "modules": [ + { + "name": "Http Interface", + "propertyName": "httpInterface", + "functionName": "newDesktopModulesHttpInterface", + "fileName": "httpInterface.js" + }, + { + "name": "Web Sockets Interface", + "propertyName": "webSocketsInterface", + "functionName": "newDesktopModulesWebSocketsInterface", + "fileName": "WebSocketsInterface.js" + }, + { + "name": "Web App Interface", + "propertyName": "webAppInterface", + "functionName": "newSocialTradingModulesWebAppInterface", + "fileName": "WebAppInterface.js" + } + ], + "utilities": [] } } ] \ No newline at end of file diff --git a/Projects/Social-Trading/DK/modules/WebAppInterface.js b/Projects/Social-Trading/DK/modules/WebAppInterface.js new file mode 100644 index 000000000..228b1ec80 --- /dev/null +++ b/Projects/Social-Trading/DK/modules/WebAppInterface.js @@ -0,0 +1,27 @@ +exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModulesWebAppInterface() { + + let thisObject = { + sendToWebApp: undefined, + messageReceived: messageReceived, + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + + } + + function initialize() { + + } + + function messageReceived(messageHeader) { + let response = { + result: 'Ok', + message: 'Hello !' + } + return + } +} \ No newline at end of file diff --git a/Projects/Social-Trading/DK/modules/WebSocketsInterface.js b/Projects/Social-Trading/DK/modules/WebSocketsInterface.js new file mode 100644 index 000000000..3714e01ee --- /dev/null +++ b/Projects/Social-Trading/DK/modules/WebSocketsInterface.js @@ -0,0 +1,84 @@ +exports.newDesktopModulesWebSocketsInterface = function newDesktopModulesWebSocketsInterface() { + + let thisObject = { + initialize: initialize, + finalize: finalize + } + + let socketServer + let webAppInterface + let webApp + + return thisObject + + function finalize() { + socketServer = undefined + webAppInterface = undefined + webApp = undefined + } + + function initialize() { + socketServer = new SA.nodeModules.ws.Server({ port: global.env.DESKTOP_WEB_SOCKETS_INTERFACE_PORT }) + webAppInterface = DK.projects.socialTrading.modules.webAppInterface.newSocialTradingModulesWebAppInterface() + + setUpWebSocketServer() + } + + function setUpWebSocketServer() { + try { + socketServer.on('connection', onConnectionOpened) + webAppInterface.sendToWebApp = sendToWebApp + + function onConnectionOpened(socket) + + if (webApp !== undefined) { + console.log('[ERROR] Only one websockets client allowed.') + return + } + /* + This function is executed every time a new Websockets connection + is stablished. + */ { + webApp = { + socket: socket + } + + webApp.socket.on('close', onConnectionClosed) + webApp.socket.on('message', onMenssage) + + async function onMenssage(message) { + try { + let messageHeader + try { + messageHeader = JSON.parse(message) + } catch (err) { + let response = { + result: 'Error', + message: 'messageHeader Not Coorrect JSON Format.' + } + webApp.socket.send(JSON.stringify(response)) + return + } + + let response = await webAppInterface.messageReceived(messageHeader.payload) + webApp.socket.send(JSON.stringify(response)) + + } catch (err) { + console.log('[ERROR] Web Sockets Interface -> setUpWebSocketServer -> err.stack = ' + err.stack) + } + } + } + + function onConnectionClosed() { + webApp = undefined + } + + function sendToWebApp(message) { + webApp.socket.send(JSON.stringify(message)) + } + + } catch (err) { + console.log('[ERROR] Web Sockets Interface -> setUpWebSocketServer -> err.stack = ' + err.stack) + } + } +} \ No newline at end of file diff --git a/Desktop/Client/httpInterface.js b/Projects/Social-Trading/DK/modules/httpInterface.js similarity index 97% rename from Desktop/Client/httpInterface.js rename to Projects/Social-Trading/DK/modules/httpInterface.js index 86ae51201..644886080 100644 --- a/Desktop/Client/httpInterface.js +++ b/Projects/Social-Trading/DK/modules/httpInterface.js @@ -1,4 +1,4 @@ -exports.newHttpInterface = function newHttpInterface() { +exports.newDesktopModulesHttpInterface = function newDesktopModulesHttpInterface() { /* This module represent the HTTP API of the