diff --git a/Projects/Governance/Plugins/User-Profiles/Loui-Molina.json b/Projects/Governance/Plugins/User-Profiles/Loui-Molina.json new file mode 100644 index 000000000..2a9820354 --- /dev/null +++ b/Projects/Governance/Plugins/User-Profiles/Loui-Molina.json @@ -0,0 +1,84 @@ +{ + "type": "User Profile", + "name": "Loui-Molina", + "config": "{\n \"signature\": {\n \"message\": \"Loui-Molina\",\n \"messageHash\": \"0x6de0af55e96cd9355a0b5ecf1118d8ef9e919dbf03cb1a292f475c515ff35970\",\n \"v\": \"0x1c\",\n \"r\": \"0xd2e9995091dac4866d903d7780d5cae7a89d04a457549a594f719c3315401da1\",\n \"s\": \"0x29ebebf46649a453f4abf9a55c2d7163eb9b5580365fb811372edc16c9203157\",\n \"signature\": \"0xd2e9995091dac4866d903d7780d5cae7a89d04a457549a594f719c3315401da129ebebf46649a453f4abf9a55c2d7163eb9b5580365fb811372edc16c92031571c\"\n }\n}", + "project": "Governance", + "tokenPowerSwitch": { + "type": "Token Power Switch", + "name": "New Token Power Switch", + "config": "{}", + "project": "Governance", + "tokenPowerSwitch": [], + "id": "f439a686-0607-469f-936f-60f0f672d975", + "savedPayload": { + "position": { + "x": 13265.000000000002, + "y": 6027.05830753354 + }, + "targetPosition": { + "x": 13185.000000000002, + "y": 6104.05830753354 + }, + "floatingObject": { + "isPinned": false, + "isFrozen": false, + "isCollapsed": false, + "angleToParent": 1, + "distanceToParent": 3, + "arrangementStyle": 0 + }, + "uiObject": { + "isRunning": false + } + } + }, + "tokensMined": { + "type": "Tokens Mined", + "name": "New Tokens Mined", + "project": "Governance", + "id": "f3c83ef5-fd88-4db5-85b9-2496f483c98e", + "savedPayload": { + "position": { + "x": 13249.000000000002, + "y": 6153.05830753354 + }, + "targetPosition": { + "x": 13185.000000000002, + "y": 6104.05830753354 + }, + "floatingObject": { + "isPinned": false, + "isFrozen": false, + "isCollapsed": false, + "angleToParent": 1, + "distanceToParent": 3, + "arrangementStyle": 0 + }, + "uiObject": { + "isRunning": false + } + } + }, + "id": "743fba6e-a3c9-4a84-9125-5cc45f219d6d", + "savedPayload": { + "position": { + "x": 13185.000000000002, + "y": 6104.05830753354 + }, + "targetPosition": { + "x": 13106.000000000002, + "y": 6031.05830753354 + }, + "floatingObject": { + "isPinned": false, + "isFrozen": false, + "isCollapsed": false, + "angleToParent": 1, + "distanceToParent": 3, + "arrangementStyle": 0 + }, + "uiObject": { + "isRunning": false + } + } +} \ No newline at end of file diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 99b4cb1da..527b02889 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1823,6 +1823,18 @@ "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", diff --git a/Projects/Social-Trading/DK/modules/WebAppInterface.js b/Projects/Social-Trading/DK/modules/WebAppInterface.js index e99d04dfc..d6ef8c92c 100644 --- a/Projects/Social-Trading/DK/modules/WebAppInterface.js +++ b/Projects/Social-Trading/DK/modules/WebAppInterface.js @@ -7,12 +7,14 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule Later, it will try to use the personal social graph as a cache, so as to minimize the requests to Network Nodes. */ - return { + let thisObject = { messageReceived: messageReceived, initialize: initialize, finalize: finalize } + return thisObject + function finalize() { } @@ -189,32 +191,34 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule the Network Nodes do not store that info themselves, they just store the structure of the social graph. */ - return new Promise((resolve, reject) => { + let promise = new Promise((resolve, reject) => { - const fileName = postHash + ".json" - const filePath = 'My-Social-Trading-Data/main/User-Posts/' + SA.projects.foundations.utilities.filesAndDirectories.pathFromDate(timestamp) + const fileName = postHash + ".json" + const filePath = 'My-Social-Trading-Data/main/User-Posts/' + SA.projects.foundations.utilities.filesAndDirectories.pathFromDate(timestamp) - const fetch = SA.nodeModules.nodeFetch - let url = 'https://raw.githubusercontent.com/' + userProfileHandle + '/' + filePath + '/' + fileName + const fetch = SA.nodeModules.nodeFetch + let url = 'https://raw.githubusercontent.com/' + userProfileHandle + '/' + filePath + '/' + fileName - fetch(url) - .then((response) => { + fetch(url) + .then((response) => { - if (response.status !== 200) { - reject('Github.com responded with status ' + response.status) - return - } + if (response.status != 200) { + reject('Github.com responded with status ' + response.status) + return + } - response.text().then(body => { - post = JSON.parse(body) - resolve(post.postText) - }) - }) - .catch(err => { - resolve('Post Text could not be fetched. ' + err.message) + response.text().then(body => { + post = JSON.parse(body) + resolve(post.postText) }) + }) + .catch(err => { + resolve('Post Text could not be fetched. ' + err.message) + }) - } + } ) + + return promise } } \ 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..f982fcecd --- /dev/null +++ b/Projects/Social-Trading/DK/modules/WebSocketsInterface.js @@ -0,0 +1,103 @@ +exports.newDesktopModulesWebSocketsInterface = function newDesktopModulesWebSocketsInterface() { + /* + This module handles the websockets communication between the + Desktop App's Client and the Desktop App's Web App. + */ + let thisObject = { + sendToWebApp: sendToWebApp, + initialize: initialize, + finalize: finalize + } + + let socketServer + let webApp + + return thisObject + + function finalize() { + socketServer = undefined + webApp = undefined + } + + function initialize() { + let port = JSON.parse(DK.desktopApp.p2pNetworkClient.node.config).webSocketsPort + socketServer = new SA.nodeModules.ws.Server({ port: port }) + setUpWebSocketServer() + } + + function setUpWebSocketServer() { + try { + socketServer.on('connection', onConnectionOpened) + + function onConnectionOpened(socket) + /* + This function is executed every time a new Websockets connection + is established. + */ { + if (webApp !== undefined) { + console.log('[ERROR] Only one websockets client allowed.') + return + } + + webApp = { + socket: socket + } + console.log('Desktop Web App Connected to Web Sockets Interface ........................... Connected to port ' + global.env.DESKTOP_WEB_SOCKETS_INTERFACE_PORT) + + 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 = { + messageId: messageHeader.messageId, + result: 'Error', + message: 'messageHeader Not Coorrect JSON Format.' + } + webApp.socket.send(JSON.stringify(response)) + return + } + + await DK.desktopApp.webAppInterface.messageReceived(messageHeader.payload) + .then(sendResponseToWebApp) + .catch(onError) + + function sendResponseToWebApp(response) { + response.messageId = messageHeader.messageId + webApp.socket.send(JSON.stringify(response)) + } + + function onError(errorMessage) { + console.log('[ERROR] Web Sockets Interface -> onMenssage -> errorMessage = ' + errorMessage) + let response = { + messageId: messageHeader.messageId, + result: 'Error', + message: errorMessage + } + webApp.socket.send(JSON.stringify(response)) + } + + } catch (err) { + console.log('[ERROR] Web Sockets Interface -> onMenssage -> err.stack = ' + err.stack) + } + } + } + + function onConnectionClosed() { + webApp = undefined + console.log('Desktop Web App Discoonnected from Web Sockets Interface ................... Disonnected from port ' + global.env.DESKTOP_WEB_SOCKETS_INTERFACE_PORT) + } + + } 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 new file mode 100644 index 000000000..639e1e360 --- /dev/null +++ b/Projects/Social-Trading/DK/modules/httpInterface.js @@ -0,0 +1,98 @@ +exports.newDesktopModulesHttpInterface = function newDesktopModulesHttpInterface() { + /* + This module represent the HTTP API of the + Desktop App Client. All HTTP request are processed + by this module. + */ + let thisObject = { + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + } + + function initialize() { + let port = JSON.parse(DK.desktopApp.p2pNetworkClient.node.config).webPort + /* + We will create an HTTP Server and leave it running forever. + */ + SA.nodeModules.http.createServer(onHttpRequest).listen(port) + /* Starting the browser now is optional */ + if (process.argv.includes("noBrowser")) { + //Running Client only with no UI. + } else { + SA.nodeModules.open('http://localhost:' + port) + } + } + + function onHttpRequest(httpRequest, httpResponse) { + try { + let requestPathAndParameters = httpRequest.url.split('?') // Remove version information + let requestPath = requestPathAndParameters[0].split('/') + let endpointOrFile = requestPath[1] + + switch (endpointOrFile) { + case 'Environment': + { + SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(global.env), httpResponse) + } + break + case 'ClientNode': + { + SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(DK.desktopApp.p2pNetworkClient.node), httpResponse) + } + break + case 'ProjectsSchema': + { + let path = global.env.PATH_TO_PROJECTS + '/' + 'ProjectsSchema.json' + SA.projects.foundations.utilities.httpResponses.respondWithFile(path, httpResponse) + } + break + case 'Projects': + { + let path = '' + for (let i = 2; i < 10; i++) { + if (requestPath[i] !== undefined) { + let parameter = unescape(requestPath[i]) + path = path + '/' + parameter + } + + } + let filePath = global.env.PATH_TO_PROJECTS + path + SA.projects.foundations.utilities.httpResponses.respondWithFile(filePath, httpResponse) + } + break + case 'Images': // This means the Images folder. + { + let path = global.env.PATH_TO_DESKTOP + '/WebServer/Images/' + requestPath[2] + + if (requestPath[3] !== undefined) { + path = path + '/' + requestPath[3] + } + + if (requestPath[4] !== undefined) { + path = path + '/' + requestPath[4] + } + + if (requestPath[5] !== undefined) { + path = path + '/' + requestPath[5] + } + + path = unescape(path) + + SA.projects.foundations.utilities.httpResponses.respondWithImage(path, httpResponse) + } + break + default: + { + SA.projects.foundations.utilities.httpResponses.respondWithWebFile(httpResponse, endpointOrFile, global.env.PATH_TO_DESKTOP) + } + } + } catch (err) { + console.log(err.stack) + } + } +}