Merge pull request #1720 from Luis-Fernando-Molina/develop

Contribution: Desktop App: Infraestructure to connect via websockets from Web App to Network Node via Desktop Client
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-09-09 09:27:43 -04:00
commit 274d8e24fa
35 files changed
+1405 -389

No files matched your search

+18 -15
View File
@@ -8,33 +8,36 @@ 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()
/* These are the Network Interfaces by which the UI interacts with the Desktop App.*/
//let WEB_SOCKETS_INTERFACE = require('./webSocketsInterface.js')
let HTTP_INTERFACE = require('./httpInterface.js')
DK.running.socialGraph = DK.projects.socialTrading.modules.socialGraph.newSocialTradingModulesSocialGraph()
await DK.running.socialGraph.initialize()
/*
WEB_SOCKETS_INTERFACE = WEB_SOCKETS_INTERFACE.newWebSocketsInterface()
WEB_SOCKETS_INTERFACE.initialize()
console.log('Web Sockets Interface ....................................... Listening at port ' + global.env.CLIENT_WEB_SOCKETS_INTERFACE_PORT)
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()
console.log('Desktop Client Connected to Network Node via Web Sockets ................... Connected to port ' + global.env.NETWORK_WEB_SOCKETS_INTERFACE_PORT)
HTTP_INTERFACE = HTTP_INTERFACE.newHttpInterface()
HTTP_INTERFACE.initialize()
console.log('Http Interface .............................................. Listening at port ' + global.env.DESKTOP_HTTP_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 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 Client Http Interface .............................................. Listening at port ' + global.env.DESKTOP_HTTP_INTERFACE_PORT)
return
let queryMessage
let query
/*
-190
View File
@@ -1,190 +0,0 @@
let postLoader
function newAppLoader() {
const MODULE_NAME = 'App Loader'
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
let thisObject = {
loadModules: loadModules
}
return thisObject
async function loadModules() {
try {
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> Entering function.') }
let plotters
let modulesArray = []
plotters = defaultPlotters()
modulesArray = modulesArray.concat([
'Globals.js',
'Workspace.js',
'Files/SingleFile.js',
'Files/FileCloud.js',
'Files/MarketFiles.js',
'Files/DailyFiles.js',
'Files/FileCursor.js',
'Files/FileSequence.js',
'Files/FileStorage.js',
'EventsServerClient.js',
'LegacyPlotter.js',
'PlotterPanel.js',
'VideoRecorder.js',
'ProductStorage.js',
'Canvas.js',
'EventHandler.js',
'Frame.js',
'Animation.js',
'Container.js',
'Utilities.js',
'AppPostLoader.js'
])
modulesArray = modulesArray.concat(plotters)
functionLibraries()
function functionLibraries() {
let url = 'ListFunctionLibraries'
httpRequest(undefined, url, onResponse)
function onResponse(err, fileList) {
let urlArray = []
let fileArray = JSON.parse(fileList)
for (let i = 0; i < fileArray.length; i++) {
let item = fileArray[i]
project = item[0]
fileName = item[1]
urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName)
}
modulesArray = modulesArray.concat(urlArray)
utilities()
}
}
function utilities() {
let url = 'ListUtilitiesFiles'
httpRequest(undefined, url, onResponse)
function onResponse(err, fileList) {
let urlArray = []
let fileArray = JSON.parse(fileList)
for (let i = 0; i < fileArray.length; i++) {
let item = fileArray[i]
project = item[0]
fileName = item[1]
urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Utilities' + '/' + fileName)
}
modulesArray = modulesArray.concat(urlArray)
globals()
}
}
function globals() {
let url = 'ListGlobalFiles'
httpRequest(undefined, url, onResponse)
function onResponse(err, fileList) {
let urlArray = []
let fileArray = JSON.parse(fileList)
for (let i = 0; i < fileArray.length; i++) {
let item = fileArray[i]
project = item[0]
fileName = item[1]
urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Globals' + '/' + fileName)
}
modulesArray = modulesArray.concat(urlArray)
spaces()
}
}
function spaces() {
let url = 'ListSpaceFiles'
httpRequest(undefined, url, onResponse)
function onResponse(err, fileList) {
let urlArray = []
let fileArray = JSON.parse(fileList)
for (let i = 0; i < fileArray.length; i++) {
let path = fileArray[i]
urlArray.push('Projects' + '/' + path)
}
modulesArray = modulesArray.concat(urlArray)
downloadIncludedFiles()
}
}
function downloadIncludedFiles() {
let downloadedCounter = 0
for (let i = 0; i < modulesArray.length; i++) {
let path = modulesArray[i]
REQUIREJS([path], onRequired)
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> Module Requested.') }
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> path = ' + path) }
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> total requested = ' + (i + 1)) }
function onRequired(pModule) {
try {
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> Entering function.') }
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> Module Downloaded.') }
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> path = ' + path) }
downloadedCounter++
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> downloadedCounter = ' + downloadedCounter) }
if (downloadedCounter === modulesArray.length) {
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> Starting Advanced Algos Platform.') }
setTimeout(() => {
postLoader = newAppPostLoader()
postLoader.start()
}, 500)
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] loadModules -> onRequired -> err = ' + err.stack) }
}
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] loadModules -> err = ' + err.stack) }
}
}
function defaultPlotters() {
return [
'Plotters/Foundations/Candles/Plotters-Candles-Volumes/Candles.js',
'Plotters/Foundations/Candles/Plotters-Candles-Volumes/CandlePanel.js',
'Plotters/Foundations/Candles/Plotters-Candles-Volumes/Volumes.js',
'Plotters/Foundations/Candles/Plotters-Candles-Volumes/VolumePanel.js',
'Plotters/Foundations/Bollinger/Plotters-Bollinger-Bands/BollingerBands.js',
'Plotters/Foundations/Bollinger/Plotters-Bollinger-Bands/BollingerBandsPanel.js',
'Plotters/Foundations/Bollinger/Plotters-Bollinger-Bands/PercentageBandwidth.js'
]
}
}
+15
View File
@@ -0,0 +1,15 @@
/* Root objects*/
let UI = {
projects: {},
schemas: { projectSchema: undefined },
environment: undefined,
running: {}
}
let SA = { projects: {} }
/*
We will use this to load functions originally intended for Nodejs
*/
let exports = {}
+138
View File
@@ -0,0 +1,138 @@
function newWebApp() {
let thisObject = {
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
}
async function initialize() {
try {
setupRootObject(UI, 'UI')
setupRootObject(SA, 'SA')
await UI.projects.socialTrading.modules.webSocketsClient.initialize()
setupHomePage()
} catch (err) {
console.log('[ERROR] initialize -> err.stack = ' + err.stack)
}
}
function setupRootObject(rootObject, rootObjectName) {
/*
Here we will setup the UI object, with all the
projects and spaces.
*/
for (let i = 0; i < UI.schemas.projectSchema.length; i++) {
let projectDefinition = UI.schemas.projectSchema[i]
rootObject.projects[projectDefinition.propertyName] = {}
let projectInstance = rootObject.projects[projectDefinition.propertyName]
projectInstance.utilities = {}
projectInstance.globals = {}
projectInstance.functionLibraries = {}
projectInstance.modules = {}
if (projectDefinition[rootObjectName] === undefined) { continue }
/* Set up Globals of this Project */
if (projectDefinition[rootObjectName].globals !== undefined) {
for (let j = 0; j < projectDefinition[rootObjectName].globals.length; j++) {
let globalDefinition = projectDefinition[rootObjectName].globals[j]
if (exports[globalDefinition.functionName] === undefined) {
projectInstance.globals[globalDefinition.propertyName] = eval(globalDefinition.functionName + '()')
} else {
projectInstance.globals[globalDefinition.propertyName] = eval('exports.' + globalDefinition.functionName + '()')
}
}
}
/* Set up Utilities of this Project */
if (projectDefinition[rootObjectName].utilities !== undefined) {
for (let j = 0; j < projectDefinition[rootObjectName].utilities.length; j++) {
let utilityDefinition = projectDefinition[rootObjectName].utilities[j]
if (exports[utilityDefinition.functionName] === undefined) {
projectInstance.utilities[utilityDefinition.propertyName] = eval(utilityDefinition.functionName + '()')
} else {
projectInstance.utilities[utilityDefinition.propertyName] = eval('exports.' + utilityDefinition.functionName + '()')
}
}
}
/* Set up Function Libraries of this Project */
if (projectDefinition[rootObjectName].functionLibraries !== undefined) {
for (let j = 0; j < projectDefinition[rootObjectName].functionLibraries.length; j++) {
let functionLibraryDefinition = projectDefinition[rootObjectName].functionLibraries[j]
if (exports[functionLibraryDefinition.functionName] === undefined) {
projectInstance.functionLibraries[functionLibraryDefinition.propertyName] = eval(functionLibraryDefinition.functionName + '()')
} else {
projectInstance.functionLibraries[functionLibraryDefinition.propertyName] = eval('exports.' + functionLibraryDefinition.functionName + '()')
}
}
}
/* Set up Modules of this Project */
if (projectDefinition[rootObjectName].modules !== undefined) {
for (let j = 0; j < projectDefinition[rootObjectName].modules.length; j++) {
let functionLibraryDefinition = projectDefinition[rootObjectName].modules[j]
if (exports[functionLibraryDefinition.functionName] === undefined) {
projectInstance.modules[functionLibraryDefinition.propertyName] = eval(functionLibraryDefinition.functionName + '()')
} else {
projectInstance.modules[functionLibraryDefinition.propertyName] = eval('exports.' + functionLibraryDefinition.functionName + '()')
}
}
}
}
}
async function setupHomePage() {
let queryMessage
let query
/*
Test Query User Profiles.
*/
queryMessage = {
queryType: SA.projects.socialTrading.globals.queryTypes.USER_PROFILES,
emitterUserProfileId: undefined,
initialIndex: 'Last',
amountRequested: 10,
direction: 'Past'
}
query = {
requestType: 'Query',
queryMessage: JSON.stringify(queryMessage)
}
await UI.projects.socialTrading.modules.webSocketsClient.sendMessage(
JSON.stringify(query)
)
.then(showProfiles)
.catch(onError)
async function showProfiles(profiles) {
console.log(profiles)
for (let i = 0; i < profiles.length; i++) {
let profile = profiles[i]
console.log(profile)
}
}
/*
Error Handling
*/
function onError(errorMessage) {
console.log('[ERROR] Query not executed. ' + errorMessage)
}
}
}
+118
View File
@@ -0,0 +1,118 @@
function newWebAppLoader() {
let thisObject = {
loadModules: loadModules
}
return thisObject
async function loadModules() {
try {
let modulesArray = [
'WebDebugLog.js',
'WebApp.js'
]
for (let i = 0; i < UI.schemas.projectSchema.length; i++) {
let project = UI.schemas.projectSchema[i]
if (project.UI !== undefined) {
if (project.UI.functionLibraries !== undefined) {
for (let j = 0; j < project.UI.functionLibraries.length; j++) {
let fileName = project.UI.functionLibraries[j].fileName
if (fileName === undefined) {fileName = project.UI.functionLibraries[j].name.replaceAll(' ', '') + '.js'}
modulesArray.push('Projects' + '/' + project.name + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName)
}
}
if (project.UI.utilities !== undefined) {
for (let j = 0; j < project.UI.utilities.length; j++) {
let fileName = project.UI.utilities[j].fileName
if (fileName === undefined) {fileName = project.UI.utilities[j].name.replaceAll(' ', '') + '.js'}
modulesArray.push('Projects' + '/' + project.name + '/' + 'UI' + '/' + 'Utilities' + '/' + fileName)
}
}
if (project.UI.globals !== undefined) {
for (let j = 0; j < project.UI.globals.length; j++) {
let fileName = project.UI.globals[j].fileName
if (fileName === undefined) {fileName = project.UI.globals[j].name.replaceAll(' ', '') + '.js'}
modulesArray.push('Projects' + '/' + project.name + '/' + 'UI' + '/' + 'Globals' + '/' + fileName)
}
}
if (project.UI.modules !== undefined) {
for (let j = 0; j < project.UI.modules.length; j++) {
let fileName = project.UI.modules[j].fileName
if (fileName === undefined) {fileName = project.UI.modules[j].name.replaceAll(' ', '') + '.js'}
modulesArray.push('Projects' + '/' + project.name + '/' + 'UI' + '/' + 'Modules' + '/' + fileName)
}
}
}
if (project.SA !== undefined) {
if (project.SA.functionLibraries !== undefined) {
for (let j = 0; j < project.SA.functionLibraries.length; j++) {
let fileName = project.SA.functionLibraries[j].fileName
if (fileName === undefined) {fileName = project.SA.functionLibraries[j].name.replaceAll(' ', '') + '.js'}
modulesArray.push('Projects' + '/' + project.name + '/' + 'SA' + '/' + 'Function-Libraries' + '/' + fileName)
}
}
if (project.SA.utilities !== undefined) {
for (let j = 0; j < project.SA.utilities.length; j++) {
let fileName = project.SA.utilities[j].fileName
if (fileName === undefined) {fileName = project.SA.utilities[j].name.replaceAll(' ', '') + '.js'}
modulesArray.push('Projects' + '/' + project.name + '/' + 'SA' + '/' + 'Utilities' + '/' + fileName)
}
}
if (project.SA.globals !== undefined) {
for (let j = 0; j < project.SA.globals.length; j++) {
let fileName = project.SA.globals[j].fileName
if (fileName === undefined) {fileName = project.SA.globals[j].name.replaceAll(' ', '') + '.js'}
modulesArray.push('Projects' + '/' + project.name + '/' + 'SA' + '/' + 'Globals' + '/' + fileName)
}
}
if (project.SA.modules !== undefined) {
for (let j = 0; j < project.SA.modules.length; j++) {
let fileName = project.SA.modules[j].fileName
if (fileName === undefined) {fileName = project.SA.modules[j].name.replaceAll(' ', '') + '.js'}
modulesArray.push('Projects' + '/' + project.name + '/' + 'SA' + '/' + 'Modules' + '/' + fileName)
}
}
}
}
downloadIncludedFiles()
function downloadIncludedFiles() {
let downloadedCounter = 0
for (let i = 0; i < modulesArray.length; i++) {
let path = modulesArray[i]
REQUIREJS([path], onRequired)
function onRequired(pModule) {
try {
downloadedCounter++
if (downloadedCounter === modulesArray.length) {
setTimeout(() => {
UI.running.webApp = newWebApp()
UI.running.webApp.initialize()
}, 500)
}
} catch (err) {
console.log('[ERROR] loadModules -> onRequired -> err = ' + err.stack)
}
}
}
}
} catch (err) {
console.log('[ERROR] loadModules -> err = ' + err.stack)
}
}
}
+102
View File
@@ -0,0 +1,102 @@
function loadSuperalgos() {
let browser = checkBrowserVersion()
if ((browser.name !== "Chrome" && browser.name !== "Safari") || (browser.name === "Chrome" && parseInt(browser.version) < 85) || (browser.name === "Safari" && parseInt(browser.version) < 13)) {
alert("Superalgos is officially supported on Google Chrome 85 or Safari 13.1 and above. Your browser version has been detected as potentially beneath this. If you continue you may experience some functionaility issues.\n\nDetected Browser: " + browser.name + "\nVersion: " + browser.version)
}
loadGlobals()
function loadGlobals() {
let path = "Globals.js"
REQUIREJS([path], onRequired)
function onRequired(pModule) {
setupEnvironment()
}
}
function setupEnvironment() {
httpRequest(undefined, 'Environment', onResponse)
function onResponse(err, file) {
UI.environment = JSON.parse(file)
setupProjectsSchema()
}
}
function setupProjectsSchema() {
httpRequest(undefined, 'ProjectsSchema', onResponse)
function onResponse(err, file) {
UI.schemas.projectSchema = JSON.parse(file)
loadModules()
}
}
function loadModules() {
let path = "WebAppLoader.js"
REQUIREJS([path], onRequired)
function onRequired(pModule) {
let APP_LOADER_MODULE = newWebAppLoader()
APP_LOADER_MODULE.loadModules()
}
}
}
function httpRequest(pContentToSend, pPath, callBackFunction) {
let xmlHttpRequest = new XMLHttpRequest()
xmlHttpRequest.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
try {
callBackFunction(undefined, xmlHttpRequest.responseText)
} catch (err) {
console.log('[ERROR] httpRequest -> httpRequest -> err.stack = ' + err.stack)
console.log('[ERROR] httpRequest -> httpRequest -> pContentToSend = ' + pContentToSend)
console.log('[ERROR] httpRequest -> httpRequest -> pPath = ' + pPath)
console.log('[ERROR] httpRequest -> httpRequest -> xmlHttpRequest.responseText = ' + xmlHttpRequest.responseText)
console.log('[ERROR] httpRequest -> httpRequest -> callBackFunction = ' + callBackFunction)
}
return
} else if (this.readyState === 4 && this.status === 404) {
callBackFunction({ result: "Fail", message: xmlHttpRequest.responseText.trim(), code: xmlHttpRequest.responseText.trim() })
return
}
}
if (pContentToSend === undefined) {
xmlHttpRequest.open("GET", pPath, true)
xmlHttpRequest.send()
} else {
try {
let blob = new Blob([pContentToSend], { type: 'text/plain' })
xmlHttpRequest.open("POST", pPath, true)
xmlHttpRequest.send(blob)
} catch (err) {
if (ERROR_LOG === true) { console.log("[ERROR] callServer -> err.message = " + err.message) }
callBackFunction({ result: "Fail", message: err.message })
}
}
}
function checkBrowserVersion() {
let ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []
if (/trident/i.test(M[1])) {
tem = /\brv[ :]+(\d+)/g.exec(ua) || []
return { name: 'IE', version: (tem[1] || '') }
}
if (M[1] === 'Chrome') {
tem = ua.match(/\bOPR|Edge\/(\d+)/)
if (tem != null) { return { name: 'Opera', version: tem[1] } }
}
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?']
if ((tem = ua.match(/version\/(\d+)/i)) != null) { M.splice(1, 1, tem[1]) }
return {
name: M[0],
version: M[1]
}
}
+21
View File
@@ -0,0 +1,21 @@
function newWebDebugLog() {
try {
let thisObject = {
write: write,
fileName: 'undefined'
}
return thisObject
function write(pText) {
console.log(spacePad(thisObject.fileName, 50) + ' : ' + pText)
function spacePad(str, max) {
str = str.toString()
return str.length < max ? spacePad(' ' + str, max) : str
}
}
} catch (err) {
console.log(spacePad(MODULE_NAME, 50) + ' : ' + '[ERROR] WebDebugLog --> err = ' + err.stack)
}
}
File renamed without changes.
+218 -8
View File
@@ -22,13 +22,223 @@
font-style: normal;
}
kbd {
padding: 2px 8px;
font-size: 125%;
font-weight: 500;
.scroll-div {
position:absolute;
overflow-y: scroll;
overflow-x: hidden;
top:0px;
left:0px;
vertical-align: top;
height: 100%;
width: 100%;
color: #000;
background-color: #bcd643;
border-radius: 5px;
border-style: outset;
border-width: 1px;
border-color: blue;
background-color: #ffffff;
border-width: 0px;
}
.content-div {
position:relative;
vertical-align: top;
height: 100%;
width: 30%;
left: 31.2%;
color: #000;
border-color: blue;
background-color: transparent;
border-width: 0px;
}
.post-div {
vertical-align: top;
height: 300px;
width: 100%;
color: #000;
border-color: blue;
background-color: transparent;
border-width: 0px;
}
.page-table {
pointer-events: none;
position:fixed;
position: absolute;
top:0px;
left:18%;
width: 64%;
height: 100%;
padding: 0;
margin: 0;
color: #000;
background:transparent;
border-width: 0px;
border-collapse: collapse;
}
.left-column {
position:relative;
top:0px;
width: 20%;
height: 100%;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
}
.middle-column {
position:relative;
top:0px;
width: 50%;
height: 100%;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
}
.right-column {
position:relative;
top:0px;
left:0px;
width: 30%;
height: 100%;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
}
.left-table {
position:relative;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
border-collapse: collapse;
}
.logo-cell {
vertical-align: top;
width: 100%;
height: 70px;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
}
.menu-cell {
vertical-align: top;
width: 100%;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
}
.profile-cell {
vertical-align: bottom;
width: 100%;
height: 50px;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
}
.middle-table {
position:relative;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
border-collapse: collapse;
}
.content-title-cell {
vertical-align: top;
width: 100%;
height: 50px;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
background-color: #ffffff;
}
.content-cell {
vertical-align: top;
width: 100%;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
}
.right-table {
position:relative;
width: 100%;
height: 100%;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
border-collapse: collapse;
}
.search-cell {
vertical-align: top;
width: 100%;
height: 50px;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
}
.context-cell {
vertical-align: top;
width: 100%;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
background:transparent;
}
.menu-table {
position:relative;
width: 100%;
height: 65%;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
border-collapse: collapse;
}
.menu-item-cell {
vertical-align: top;
width: 100%;
height: 50px;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
}
.who-to-follow-table {
position:relative;
width: 100%;
height: 30%;
padding: 0;
margin: 0;
color: #000;
border-width: 0px;
border-collapse: collapse;
}
+103 -9
View File
@@ -6,8 +6,8 @@
<meta name="description" content="Free and Open Source Crypto Social Trading">
<link rel="stylesheet" href="main.css" type="text/css" charset="utf-8" />
<link rel="shortcut icon" type="image/png/ico" href="Images/favicon.ico" />
<script type="text/javascript" src="WebServer/require.js"></script>
<script type="text/javascript" src="AppPreLoader.js"></script>
<script type="text/javascript" src="Require.js"></script>
<script type="text/javascript" src="WebAppPreLoader.js"></script>
<script type="text/javascript">
function loadApp() {
@@ -37,15 +37,109 @@
console.log('Error Resizing. ' + err.stack)
}
}
</script>
</script>
</head>
<body id="body" onload="loadApp()"
onresize="onResize()">
Hello World!
<div id="masterApp"></div>
<div id="canvasApp"></div>
<body id="body" onload="loadApp()" onresize="onResize()">
<div class="scroll-div">
<div class="content-div">
<div class="post-div">
POST 1
</div>
<div class="post-div">
POST 2
</div>
<div class="post-div">
POST 3
</div>
<div class="post-div">
POST 4
</div>
<div class="post-div">
POST 5
</div>
</div>
</div>
<table id="page-table" class="page-table">
<tr>
<td class="left-column">
<table class="left-table">
<tr>
<td class="logo-cell">LOGO</td>
</tr>
<tr>
<td class="menu-cell">
<table class="menu-table">
<tr>
<td class="menu-item-cell">Home</td>
</tr>
<tr>
<td class="menu-item-cell">Explore</td>
</tr>
<tr>
<td class="menu-item-cell">Notifications</td>
</tr>
<tr>
<td class="menu-item-cell">Messages</td>
</tr>
<tr>
<td class="menu-item-cell">Bookmarks</td>
</tr>
<tr>
<td class="menu-item-cell">Lists</td>
</tr>
<tr>
<td class="menu-item-cell">Profile</td>
</tr>
<tr>
<td class="menu-item-cell">More</td>
</tr>
<tr>
<td class="menu-item-cell">Post</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="profile-cell">PROFILE</td>
</tr>
</table>
</td>
<td class="middle-column">
<table class="middle-table">
<tr>
<td class="content-title-cell">CONTENT TITLE</td>
</tr>
<tr>
<td class="content-cell">
</td>
</tr>
</table>
</td>
<td class="right-column">
<table class="right-table">
<tr>
<td class="search-cell">SEARCH</td>
</tr>
<tr>
<td class="context-cell">
<table id="who-to-follow-table" class="who-to-follow-table">
<tr>
<td class="menu-item-cell">User Profile 1</td>
</tr>
<tr>
<td class="menu-item-cell">User Profile 2</td>
</tr>
<tr>
<td class="menu-item-cell">User Profile 3</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
-68
View File
@@ -1,68 +0,0 @@
exports.newHttpInterface = function newHttpInterface() {
/*
This module represent the HTTP API of the
Desktop App. All HTTP request are processed
by this module.
*/
let thisObject = {
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
}
function initialize() {
/*
We will create an HTTP Server and leave it running forever.
*/
SA.nodeModules.http.createServer(onHttpRequest).listen(global.env.DESKTOP_HTTP_INTERFACE_PORT)
/* Starting the browser now is optional */
if (process.argv.includes("noBrowser")) {
//Running Client only with no UI.
} else {
SA.nodeModules.open('http://localhost:' + global.env.DESKTOP_HTTP_INTERFACE_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 'Images': // This means the Images folder.
{
let path = global.env.PATH_TO_CLIENT + '/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)
}
}
}
+2
View File
@@ -4,6 +4,8 @@ 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,
DESKTOP_WEB_SOCKETS_INTERFACE_HOST: 'localhost',
CLIENT_HTTP_INTERFACE_PORT: 34248,
DESKTOP_HTTP_INTERFACE_PORT: 34249,
PATH_TO_TASK_SERVER: './TaskServer',
+1 -1
View File
@@ -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 */
+11 -11
View File
@@ -5,7 +5,7 @@ function newAppLoader() {
const INFO_LOG = false
const ERROR_LOG = true
const logger = newWebDebugLog()
let thisObject = {
loadModules: loadModules
@@ -64,16 +64,16 @@ function newAppLoader() {
let fileArray = JSON.parse(fileList)
for (let i = 0; i < fileArray.length; i++) {
let item = fileArray[i]
project = item[0]
fileName = item[1]
urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName)
urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName)
}
modulesArray = modulesArray.concat(urlArray)
utilities()
}
}
}
function utilities() {
let url = 'ListUtilitiesFiles'
@@ -84,16 +84,16 @@ function newAppLoader() {
let fileArray = JSON.parse(fileList)
for (let i = 0; i < fileArray.length; i++) {
let item = fileArray[i]
project = item[0]
fileName = item[1]
urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Utilities' + '/' + fileName)
urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Utilities' + '/' + fileName)
}
modulesArray = modulesArray.concat(urlArray)
globals()
}
}
}
function globals() {
let url = 'ListGlobalFiles'
@@ -104,16 +104,16 @@ function newAppLoader() {
let fileArray = JSON.parse(fileList)
for (let i = 0; i < fileArray.length; i++) {
let item = fileArray[i]
project = item[0]
fileName = item[1]
urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Globals' + '/' + fileName)
urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Globals' + '/' + fileName)
}
modulesArray = modulesArray.concat(urlArray)
spaces()
}
}
}
function spaces() {
let url = 'ListSpaceFiles'
@@ -138,7 +138,7 @@ function newAppLoader() {
for (let i = 0; i < modulesArray.length; i++) {
let path = modulesArray[i]
console.log(path)
REQUIREJS([path], onRequired)
if (INFO_LOG === true) { logger.write('[INFO] loadModules -> Module Requested.') }
@@ -88,7 +88,8 @@ exports.newFoundationsBotModulesTradingSimulation = function (processIndex) {
This will happen when the sessionParameters.timeRange.config.initialDatetime is beyond the last candle available,
meaning that the dataSet needs to be updated with more up-to-date data.
*/
TS.projects.foundations.functionLibraries.sessionFunctions.stopSession(processIndex, 'Data is not up-to-date enough. Please start the Masters Data Mining Operation.')
console.log('DEBUGGING ..................', initialCandle, candles.length)
TS.projects.foundations.functionLibraries.sessionFunctions.stopSession(processIndex, 'Data is not up-to-date enough. Please start the Data Mining Operation.')
TS.projects.foundations.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
'[IMPORTANT] runSimulation -> Data is not up-to-date enough. Stopping the Session now. ')
return
@@ -129,7 +129,7 @@ function newFoundationsFunctionLibraryChartingSpaceFunctions() {
if (environment.id !== node.payload.referenceParent.id) { continue }
let market = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(session, 'Market Trading Tasks', undefined, true, false, true, false)
if (market.payload.referenceParent === undefined) { continue }
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, session, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, session, true) === true) {
createTimeMachine(node, session, market.payload.referenceParent, networkNode, rootNodes)
}
}
@@ -320,13 +320,13 @@ function newFoundationsFunctionLibraryChartingSpaceFunctions() {
let testingTradingTasks = UI.projects.foundations.utilities.branches.findInBranch(networkNode, 'Testing Trading Tasks', node, true)
let productionTradingTasks = UI.projects.foundations.utilities.branches.findInBranch(networkNode, 'Production Trading Tasks', node, true)
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, testingTradingTasks, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, testingTradingTasks, true) === true) {
let dashboard = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Dashboard')
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(dashboard, testingTradingTasks)
dashboard.name = testingTradingTasks.type + ' ' + networkNode.name
}
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, productionTradingTasks, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, productionTradingTasks, true) === true) {
let dashboard = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Dashboard')
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(dashboard, productionTradingTasks)
dashboard.name = productionTradingTasks.type + ' ' + networkNode.name
@@ -345,7 +345,7 @@ function newFoundationsFunctionLibraryChartingSpaceFunctions() {
if (rootNode.type === project + ' Project') {
let projectDefinition = rootNode.projectDefinition
if (projectDefinition !== undefined) {
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, projectDefinition, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, projectDefinition, true) === true) {
let projectTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Project Dashboards', undefined, project)
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(projectTasks, projectDefinition)
}
@@ -290,9 +290,9 @@ function newFoundationsFunctionLibraryCryptoEcosystemFunctions() {
}
function installTheRestOfTheBranch(projectDataTasks) {
let exchangeDataTasks = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectDataTasks, 'Exchange Data Tasks', cryptoExchange)
let exchangeDataTasks = UI.projects.foundations.utilities.nodeChildren.findOrCreateChildWithReference(projectDataTasks, 'Exchange Data Tasks', cryptoExchange)
exchangeDataTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
let marketDataTask = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeDataTasks, 'Market Data Tasks', market, rootNodes)
let marketDataTask = UI.projects.foundations.utilities.nodeChildren.findAndRecreateChildWithReference(exchangeDataTasks, 'Market Data Tasks', market, rootNodes)
UI.projects.foundations.utilities.menu.menuClick(marketDataTask, 'Add Missing Data Mine Tasks', true)
UI.projects.foundations.utilities.menu.menuClickOfNodeArray(marketDataTask.dataMineTasks, 'Add All Tasks', true)
@@ -323,9 +323,9 @@ function newFoundationsFunctionLibraryCryptoEcosystemFunctions() {
}
function installTheRestOfTheBranch(projectLearningTasks) {
let exchangeLearningTasks = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectLearningTasks, 'Exchange Learning Tasks', cryptoExchange)
let exchangeLearningTasks = UI.projects.foundations.utilities.nodeChildren.findOrCreateChildWithReference(projectLearningTasks, 'Exchange Learning Tasks', cryptoExchange)
exchangeLearningTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
let marketLearningTask = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeLearningTasks, 'Market Learning Tasks', market, rootNodes)
let marketLearningTask = UI.projects.foundations.utilities.nodeChildren.findAndRecreateChildWithReference(exchangeLearningTasks, 'Market Learning Tasks', market, rootNodes)
UI.projects.foundations.utilities.menu.menuClick(marketLearningTask, 'Add Missing Learning Mine Tasks', true)
UI.projects.foundations.utilities.menu.menuClickOfNodeArray(marketLearningTask.learningMineTasks, 'Add All Tasks', true)
@@ -377,9 +377,9 @@ function newFoundationsFunctionLibraryCryptoEcosystemFunctions() {
}
function installTheRestOfTheBranch(projectTradingTasks) {
let exchangeTradingTasks = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectTradingTasks, 'Exchange Trading Tasks', cryptoExchange)
let exchangeTradingTasks = UI.projects.foundations.utilities.nodeChildren.findOrCreateChildWithReference(projectTradingTasks, 'Exchange Trading Tasks', cryptoExchange)
exchangeTradingTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
let marketTradingTask = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeTradingTasks, 'Market Trading Tasks', market, rootNodes)
let marketTradingTask = UI.projects.foundations.utilities.nodeChildren.findAndRecreateChildWithReference(exchangeTradingTasks, 'Market Trading Tasks', market, rootNodes)
UI.projects.foundations.utilities.menu.menuClick(marketTradingTask, 'Add Missing Trading Mine Tasks', true)
UI.projects.foundations.utilities.menu.menuClickOfNodeArray(marketTradingTask.tradingMineTasks, 'Add All Tasks', true)
@@ -429,9 +429,9 @@ function newFoundationsFunctionLibraryCryptoEcosystemFunctions() {
}
function installTheRestOfTheBranch(projectDataProducts) {
let exchangeDataProducts = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectDataProducts, 'Exchange Data Products', cryptoExchange)
let exchangeDataProducts = UI.projects.foundations.utilities.nodeChildren.findOrCreateChildWithReference(projectDataProducts, 'Exchange Data Products', cryptoExchange)
exchangeDataProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
let marketDataProducts = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeDataProducts, 'Market Data Products', market, rootNodes)
let marketDataProducts = UI.projects.foundations.utilities.nodeChildren.findAndRecreateChildWithReference(exchangeDataProducts, 'Market Data Products', market, rootNodes)
marketDataProducts.payload.floatingObject.collapseToggle()
UI.projects.foundations.utilities.menu.menuClick(marketDataProducts, 'Add All Data Mine Products', true)
@@ -469,16 +469,16 @@ function newFoundationsFunctionLibraryCryptoEcosystemFunctions() {
function installTheRestOfTheBranch(projectLearningProducts) {
let exchangeLearningProducts = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectLearningProducts, 'Exchange Learning Products', cryptoExchange)
let exchangeLearningProducts = UI.projects.foundations.utilities.nodeChildren.findOrCreateChildWithReference(projectLearningProducts, 'Exchange Learning Products', cryptoExchange)
exchangeLearningProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
let marketLearningProducts = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeLearningProducts, 'Market Learning Products', market, rootNodes)
let marketLearningProducts = UI.projects.foundations.utilities.nodeChildren.findAndRecreateChildWithReference(exchangeLearningProducts, 'Market Learning Products', market, rootNodes)
marketLearningProducts.payload.floatingObject.collapseToggle()
/*
Create the new session references.
*/
for (let i = 0; i < learningSessionsCreatedArray.length; i++) {
let session = learningSessionsCreatedArray[i]
if (UI.projects.foundations.utilities.children.isMissingChildrenById(marketLearningProducts, session, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(marketLearningProducts, session, true) === true) {
UI.projects.foundations.functionLibraries.dataStorageFunctions.createSessionReference(marketLearningProducts, session, 'Learning Session Reference')
}
}
@@ -524,16 +524,16 @@ function newFoundationsFunctionLibraryCryptoEcosystemFunctions() {
function installTheRestOfTheBranch(projectTradingProducts) {
let exchangeTradingProducts = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectTradingProducts, 'Exchange Trading Products', cryptoExchange)
let exchangeTradingProducts = UI.projects.foundations.utilities.nodeChildren.findOrCreateChildWithReference(projectTradingProducts, 'Exchange Trading Products', cryptoExchange)
exchangeTradingProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180
let marketTradingProducts = UI.projects.foundations.utilities.children.findAndRecreateChildWithReference(exchangeTradingProducts, 'Market Trading Products', market, rootNodes)
let marketTradingProducts = UI.projects.foundations.utilities.nodeChildren.findAndRecreateChildWithReference(exchangeTradingProducts, 'Market Trading Products', market, rootNodes)
marketTradingProducts.payload.floatingObject.collapseToggle()
/*
Create the new session references.
*/
for (let i = 0; i < tradingSessionsCreatedArray.length; i++) {
let session = tradingSessionsCreatedArray[i]
if (UI.projects.foundations.utilities.children.isMissingChildrenById(marketTradingProducts, session, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(marketTradingProducts, session, true) === true) {
UI.projects.foundations.functionLibraries.dataStorageFunctions.createSessionReference(marketTradingProducts, session, 'Trading Session Reference')
}
}
@@ -574,7 +574,7 @@ function newFoundationsFunctionLibraryCryptoEcosystemFunctions() {
If the Dashboard we need is not already there we create a new one.
*/
let arrayItem = dashboardsArray[i]
let dashboard = UI.projects.foundations.utilities.children.findOrCreateChildWithReference(projectDashboards, 'Dashboard', arrayItem.environmentNode)
let dashboard = UI.projects.foundations.utilities.nodeChildren.findOrCreateChildWithReference(projectDashboards, 'Dashboard', arrayItem.environmentNode)
dashboard.name = arrayItem.environmentNode.type + ' ' + arrayItem.networkNode.name
/*
We delete all the existing Time Machines related to the market we are currently installing.
@@ -123,7 +123,7 @@ function newFoundationsFunctionLibraryDataStorageFunctions() {
/* We will filter out all the sessions that does not belong to the market we are in */
let marketTradingTasks = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(session, 'Market Trading Tasks', undefined, true, false, true, false)
if (node.payload.referenceParent.id !== marketTradingTasks.payload.referenceParent.id) { continue }
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, session, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, session, true) === true) {
createSessionReference(node, session, 'Trading Session Reference')
}
}
@@ -146,7 +146,7 @@ function newFoundationsFunctionLibraryDataStorageFunctions() {
/* We will filter out all the sessions that does not belong to the market we are in */
let marketLearningTasks = UI.projects.foundations.utilities.meshes.findNodeInNodeMesh(session, 'Market Learning Tasks', undefined, true, false, true, false)
if (node.payload.referenceParent.id !== marketLearningTasks.payload.referenceParent.id) { continue }
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, session, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, session, true) === true) {
createSessionReference(node, session, 'Learning Session Reference')
}
}
@@ -177,7 +177,7 @@ function newFoundationsFunctionLibraryDataStorageFunctions() {
for (let i = 0; i < marketsArray.length; i++) {
let market = marketsArray[i]
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, market, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, market, true) === true) {
let marketDataProducts = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(marketDataProducts, market)
}
@@ -205,7 +205,7 @@ function newFoundationsFunctionLibraryDataStorageFunctions() {
let cryptoExchanges = cryptoEcosystem.cryptoExchanges[j]
for (let k = 0; k < cryptoExchanges.exchanges.length; k++) {
let cryptoExchange = cryptoExchanges.exchanges[k]
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, cryptoExchange, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, cryptoExchange, true) === true) {
let exchange = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(exchange, cryptoExchange)
}
@@ -238,7 +238,7 @@ function newFoundationsFunctionLibraryDataStorageFunctions() {
if (rootNode.type === project + ' Project') {
let projectDefinition = rootNode.projectDefinition
if (projectDefinition !== undefined) {
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, projectDefinition, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, projectDefinition, true) === true) {
let projectTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType, undefined, project)
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(projectTasks, projectDefinition)
}
@@ -22,7 +22,7 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
for (let k = 0; k < PROJECTS_SCHEMA.length; k++) {
let projectDefinition = PROJECTS_SCHEMA[k]
let project = projectDefinition.name
if (UI.projects.foundations.utilities.children.isMissingChildrenByName(node, project) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenByName(node, project) === true) {
let child = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Plugin Project')
child.name = project
let config = JSON.parse(child.config)
@@ -42,7 +42,7 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
for (let i = 0; i < projectDefinition.plugins.length; i++) {
let pluginType = "Plugin" + " " + projectDefinition.plugins[i]
if (UI.projects.foundations.utilities.children.isMissingChildrenByType(node, pluginType) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenByType(node, pluginType) === true) {
UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, pluginType, undefined, project)
}
}
@@ -209,10 +209,10 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
function installAsPlugin(node, rootNodes) {
let plugins = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadByNodeType('Plugins')
let pluginProject = UI.projects.foundations.utilities.children.findChildByCodeName(plugins, node.project)
let pluginProject = UI.projects.foundations.utilities.nodeChildren.findChildByCodeName(plugins, node.project)
let pluginFolderName = UI.projects.foundations.utilities.plugins.getPluginFolderNamesByNodeType(node.type)
let pluginForlderNodeType = 'Plugin ' + pluginFolderName.replaceAll('-', ' ')
let pluginFolderNode = UI.projects.foundations.utilities.children.findChildByType(pluginProject, pluginForlderNodeType)
let pluginFolderNode = UI.projects.foundations.utilities.nodeChildren.findChildByType(pluginProject, pluginForlderNodeType)
let pluginFile = UI.projects.foundations.utilities.plugins.addMissingPluginFile(pluginFolderNode, node.name, pluginFolderName, node.type, true)
node.isPlugin = true
@@ -1,5 +1,5 @@
// These function are used across the system to establish and remove references between nodes
function newFoundationsFunctionLibraryAttachDetach() {
function newFoundationsFunctionLibraryReferenceAttachDetach() {
let thisObject = {
referenceDetachNode: referenceDetachNode,
referenceAttachNode: referenceAttachNode
@@ -609,7 +609,7 @@ function newFoundationsFunctionLibraryTaskFunctions() {
if (rootNode.type === project + ' Project') {
let projectDefinition = rootNode.projectDefinition
if (projectDefinition !== undefined) {
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, projectDefinition, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, projectDefinition, true) === true) {
let projectTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType, undefined, project)
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(projectTasks, projectDefinition)
}
@@ -640,7 +640,7 @@ function newFoundationsFunctionLibraryTaskFunctions() {
let cryptoExchanges = cryptoEcosystem.cryptoExchanges[j]
for (let k = 0; k < cryptoExchanges.exchanges.length; k++) {
let cryptoExchange = cryptoExchanges.exchanges[k]
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, cryptoExchange, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, cryptoExchange, true) === true) {
let exchangeTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(exchangeTasks, cryptoExchange)
}
@@ -672,7 +672,7 @@ function newFoundationsFunctionLibraryTaskFunctions() {
for (let i = 0; i < markets.length; i++) {
let market = markets[i]
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, market, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, market, true) === true) {
let marketDataTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(marketDataTasks, market)
}
@@ -697,7 +697,7 @@ function newFoundationsFunctionLibraryTaskFunctions() {
if (rootNode.type === rootNodeType) {
let mine = rootNode
if (UI.projects.foundations.utilities.children.isMissingChildrenById(node, mine, true) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenById(node, mine, true) === true) {
let dataMineTasks = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, newNodeType)
UI.projects.foundations.functionLibraries.attachDetach.referenceAttachNode(dataMineTasks, mine)
}
@@ -163,8 +163,8 @@ function newTimeMachine() {
function setInitialPosition() {
if (thisObject.container.frame.position.x === 0 && thisObject.container.frame.position.y === 0) {
let timeMachineIndex = UI.projects.foundations.utilities.children.findChildIndexAtParentNode(thisObject.payload.node)
let dashboardIndex = UI.projects.foundations.utilities.children.findChildIndexAtParentNode(thisObject.payload.parentNode)
let timeMachineIndex = UI.projects.foundations.utilities.nodeChildren.findChildIndexAtParentNode(thisObject.payload.node)
let dashboardIndex = UI.projects.foundations.utilities.nodeChildren.findChildIndexAtParentNode(thisObject.payload.parentNode)
thisObject.container.frame.position.x = thisObject.container.frame.width * timeMachineIndex * 2
thisObject.container.frame.position.y = thisObject.container.frame.height * dashboardIndex * 2
+1 -1
View File
@@ -33,7 +33,7 @@ function newFoundationsUtilitiesPlugins() {
}
function addMissingPluginFile(node, fileName, pluginFolder, nodeType, saveWithWorkspace) {
if (UI.projects.foundations.utilities.children.isMissingChildrenByName(node, fileName) === true) {
if (UI.projects.foundations.utilities.nodeChildren.isMissingChildrenByName(node, fileName) === true) {
let child = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Plugin File', undefined, 'Foundations')
child.name = fileName
child.config = JSON.stringify({
@@ -535,7 +535,7 @@ function newGovernanceFunctionLibraryClaimsProgram() {
let destinationNodeChild = destinationNode[property.name]
let originNodeChildType = getOriginNodeChildType(destinationNodeChild)
let originNodeChild = UI.projects.foundations.utilities.children.findChildReferencingThisNode(originNode, destinationNodeChild)
let originNodeChild = UI.projects.foundations.utilities.nodeChildren.findChildReferencingThisNode(originNode, destinationNodeChild)
if (originNodeChild === undefined) {
originNodeChild = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(originNode, originNodeChildType)
@@ -552,7 +552,7 @@ function newGovernanceFunctionLibraryClaimsProgram() {
let destinationNodeChild = propertyArray[m]
let originNodeChildType = getOriginNodeChildType(destinationNodeChild)
let originNodeChild = UI.projects.foundations.utilities.children.findChildReferencingThisNode(originNode, destinationNodeChild)
let originNodeChild = UI.projects.foundations.utilities.nodeChildren.findChildReferencingThisNode(originNode, destinationNodeChild)
if (originNodeChild === undefined) {
originNodeChild = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(originNode, originNodeChildType)
@@ -552,7 +552,7 @@ function newGovernanceFunctionLibraryVotingProgram() {
let destinationNodeChild = destinationNode[property.name]
let originNodeChildType = getOriginNodeChildType(destinationNodeChild)
let originNodeChild = UI.projects.foundations.utilities.children.findChildReferencingThisNode(originNode, destinationNodeChild)
let originNodeChild = UI.projects.foundations.utilities.nodeChildren.findChildReferencingThisNode(originNode, destinationNodeChild)
if (originNodeChild === undefined) {
originNodeChild = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(originNode, originNodeChildType)
@@ -569,7 +569,7 @@ function newGovernanceFunctionLibraryVotingProgram() {
let destinationNodeChild = propertyArray[m]
let originNodeChildType = getOriginNodeChildType(destinationNodeChild)
let originNodeChild = UI.projects.foundations.utilities.children.findChildReferencingThisNode(originNode, destinationNodeChild)
let originNodeChild = UI.projects.foundations.utilities.nodeChildren.findChildReferencingThisNode(originNode, destinationNodeChild)
if (originNodeChild === undefined) {
originNodeChild = UI.projects.foundations.functionLibraries.uiObjectsFromNodes.addUIObject(originNode, originNodeChildType)
@@ -1,6 +1,9 @@
exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSocketsInterface() {
let thisObject = {
networkClients: undefined,
networkPeers: undefined,
callersMap: undefined,
initialize: initialize,
finalize: finalize
}
@@ -14,6 +17,10 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
return thisObject
function finalize() {
thisObject.networkClients = undefined
thisObject.networkPeers = undefined
callersMap = undefined
socketServer = undefined
clientInterface = undefined
peerInterface = undefined
@@ -26,18 +33,35 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
clientInterface = NT.projects.socialTrading.modules.clientInterface.newSocialTradingModulesClientInterface()
peerInterface = NT.projects.socialTrading.modules.peerInterface.newSocialTradingModulesPeerInterface()
thisObject.networkClients = []
thisObject.networkPeers = []
thisObject.callersMap = new Map()
setUpWebSocketServer()
}
function setUpWebSocketServer() {
try {
socketServer.on('connection', onConnection)
socketServer.on('connection', onConnectionOpened)
function onConnectionOpened(socket)
/*
This function is executed every time a new Websockets connection
is stablished.
*/ {
let caller = {
socket: socket,
userProfile: undefined,
role: undefined
}
caller.socket.id = SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId()
caller.socket.on('close', onConnectionClosed)
function onConnection(socket) {
let caller = {}
let calledTimestamp = (new Date()).valueOf()
socket.on('message', onMenssage)
caller.socket.on('message', onMenssage)
async function onMenssage(message) {
try {
@@ -49,7 +73,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'messageHeader Not Coorrect JSON Format.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
/*
@@ -60,13 +84,13 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'messageType Not Provided.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
switch (messageHeader.messageType) {
case "Handshake": {
handshakeProducedure(socket, caller, calledTimestamp, messageHeader)
handshakeProducedure(caller, calledTimestamp, messageHeader)
break
}
case "Request": {
@@ -76,22 +100,27 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'Handshake Not Done Yet.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
let response
switch (caller.role) {
case 'Network Client': {
let response = await clientInterface.messageReceived(messageHeader.payload, caller.userProfile)
socket.send(JSON.stringify(response))
response = await clientInterface.messageReceived(messageHeader.payload, caller.userProfile)
caller.socket.send(JSON.stringify(response))
break
}
case 'Network Peer': {
let response = await peerInterface.messageReceived(messageHeader.payload)
socket.send(JSON.stringify(response))
response = await peerInterface.messageReceived(messageHeader.payload)
caller.socket.send(JSON.stringify(response))
break
}
}
if (response.result === 'Ok' && messageHeader.payload.requestType === 'Event') {
broadcastToPeers(messageHeader, caller)
broadcastToClients(messageHeader, caller)
}
break
}
default: {
@@ -99,7 +128,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'messageType Not Supported.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
break
}
}
@@ -109,7 +138,13 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
}
}
function handshakeProducedure(socket, caller, calledTimestamp, messageHeader) {
function onConnectionClosed() {
let socketId = this.id
let caller = thisObject.callersMap.get(socketId)
removeCaller(caller)
}
function handshakeProducedure(caller, calledTimestamp, messageHeader) {
/*
The handshage producedure have 2 steps, we need to know
now which one we are at.
@@ -119,7 +154,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'step Not Provided.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
if (messageHeader.step !== 'One' && messageHeader.step !== 'Two') {
@@ -127,7 +162,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'step Not Supported.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
switch (messageHeader.step) {
@@ -149,7 +184,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'callerRole Not Provided.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
@@ -158,7 +193,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'callerRole Not Supported.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
@@ -171,7 +206,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'callerProfileHandle Not Provided.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
@@ -184,7 +219,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'callerTimestamp Not Provided.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
/*
@@ -195,7 +230,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'callerTimestamp Too Old.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
/*
@@ -215,7 +250,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
message: 'Handshake Step One Complete',
signature: JSON.stringify(signature)
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
}
function handshakeStepTwo() {
@@ -227,7 +262,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'Handshake Step One Not Completed.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
/*
@@ -238,7 +273,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'signature Not Provided.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
@@ -250,7 +285,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'Bad Signature.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
/*
@@ -263,7 +298,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'userProfile Not Found.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
/*
@@ -277,7 +312,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'callerProfileHandle Does Not Match witnessUserProfile.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
/*
@@ -289,7 +324,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'calledProfileHandle Does Not Match This Network Node Handle.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
/*
@@ -300,7 +335,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
result: 'Error',
message: 'calledTimestamp Does Not Match calledTimestamp On Record.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
return
}
/*
@@ -310,12 +345,96 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
We will remember the user profile behind this caller.
*/
caller.userProfile = witnessUserProfile
/*
We will remember the caller itself.
*/
addCaller(caller)
let response = {
result: 'Ok',
message: 'Handshake Successful.'
}
socket.send(JSON.stringify(response))
caller.socket.send(JSON.stringify(response))
}
}
function addCaller(caller) {
thisObject.callersMap.set(caller.socket.id, caller)
switch (caller.role) {
case 'Network Client': {
addToArray(thisObject.networkClients, caller)
break
}
case 'Network Peer': {
addToArray(thisObject.networkPeers, caller)
break
}
}
function addToArray(callersArray, caller) {
/*
We will add the caller to the existing array, first the ones with highest ranking.
*/
for (let i = 0; i < callersArray.length; i++) {
let callerInArray = callersArray[i]
if (caller.userProfile.ranking > callerInArray.userProfile.ranking) {
callersArray.splice(i, 0, caller)
return
}
}
callersArray.push(caller)
}
}
function removeCaller(caller) {
thisObject.callersMap.delete(caller.socket.id)
switch (caller.role) {
case 'Network Client': {
removeFromArray(thisObject.networkClients, caller)
break
}
case 'Network Peer': {
removeFromArray(thisObject.networkPeers, caller)
break
}
}
function removeFromArray(callersArray, caller) {
for (let i = 0; i < callersArray.length; i++) {
let callerInArray = callersArray[i]
if (caller.socket.id === callerInArray.socket.id) {
callersArray.splice(i, 1)
return
}
}
}
}
function broadcastToPeers(messageHeader, caller) {
let callerIdToAVoid
if (caller.role === 'Network Peer') {
callerIdToAVoid = caller.socket.id
}
for (let i = 0; i < thisObject.networkPeers.length; i++) {
let networkPeer = thisObject.networkPeers[i]
if (networkPeer.socket.id === callerIdToAVoid) { continue }
networkPeer.socket.send(messageHeader)
}
}
function broadcastToClients(messageHeader, caller) {
let callerIdToAVoid
if (caller.role === 'Network Client') {
callerIdToAVoid = caller.socket.id
}
for (let i = 0; i < thisObject.networkClients.length; i++) {
let networkClient = thisObject.networkClients[i]
if (networkClient.socket.id === callerIdToAVoid) { continue }
networkClient.socket.send(messageHeader)
}
}
@@ -8,7 +8,7 @@ exports.newNetworkModulesWebSocketsClient = function newNetworkModulesWebSockets
let socketClient
let web3 = new SA.nodeModules.web3()
let web3
let called = {}
let selectedNetworkNode // This is a Network Node we pick to try to connect to.
@@ -33,6 +33,8 @@ exports.newNetworkModulesWebSocketsClient = function newNetworkModulesWebSockets
"address": "0xa153469c57A91F5a59Fc6c45A37aD8dbad85e417"
}
*/
web3 = new SA.nodeModules.web3()
selectedNetworkNode = {
userProfileHandle: "Test-Network-Node-Profile",
blockchainAccount: "0xa153469c57A91F5a59Fc6c45A37aD8dbad85e417",
@@ -185,7 +187,6 @@ exports.newNetworkModulesWebSocketsClient = function newNetworkModulesWebSockets
reject()
return
}
console.log('[INFO] Web Sockets Client -> stepTwoResponse -> response.message = ' + response.message)
/*
This was the end of the Handshake producere. We are connected to the
Network Node and from now on, all response messages will be received
@@ -217,6 +218,7 @@ exports.newNetworkModulesWebSocketsClient = function newNetworkModulesWebSockets
if (socketClient.readyState !== 1) { // 1 means connected and ready.
console.log('[ERROR] Web Sockets Client -> sendMessage -> Cannot send message while connection is closed.')
reject('Websockets Connection Not Ready.')
return
}
let socketMessage = {
@@ -226,7 +228,7 @@ exports.newNetworkModulesWebSocketsClient = function newNetworkModulesWebSockets
socketClient.onmessage = socketMessage => { onMenssage(socketMessage) }
socketClient.send(
JSON.stringify(socketMessage)
)
)
function onMenssage(socketMessage) {
try {
+45 -10
View File
@@ -12,9 +12,9 @@
],
"functionLibraries": [
{
"name": "Attach Detach",
"name": "Reference Attach Detach",
"propertyName": "attachDetach",
"functionName": "newFoundationsFunctionLibraryAttachDetach"
"functionName": "newFoundationsFunctionLibraryReferenceAttachDetach"
},
{
"name": "Chain Attach Detach",
@@ -51,11 +51,6 @@
"propertyName": "onFocus",
"functionName": "newFoundationsFunctionLibraryOnFocus"
},
{
"name": "Super Scripts Functions",
"propertyName": "superScriptsFunctions",
"functionName": "newFoundationsFunctionLibrarySuperScriptsFunctions"
},
{
"name": "Webhook Functions",
"propertyName": "webhookFunctions",
@@ -184,8 +179,8 @@
"functionName": "newFoundationsUtilitiesMeshes"
},
{
"name": "Children",
"propertyName": "children",
"name": "Node Children",
"propertyName": "nodeChildren",
"functionName": "newFoundationsUtilitiesNodeChildren"
},
{
@@ -1238,7 +1233,7 @@
"functionName": "newGovernanceUtilitiesTables"
},
{
"name": "Decendent Tables",
"name": "Descendent Tables",
"propertyName": "decendentTables",
"functionName": "newGovernanceUtilitiesDecendentTables"
},
@@ -1471,6 +1466,46 @@
"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"
},
{
"name": "Social Graph",
"propertyName": "socialGraph",
"functionName": "newSocialTradingModulesSocialGraph",
"fileName": "SocialGraph.js"
}
],
"utilities": []
},
"UI":{
"modules":[
{
"name": "Web Sockets Client",
"propertyName": "webSocketsClient",
"functionName": "newSocialTradingModulesWebSocketsClient",
"fileName": "WebSocketsClient.js"
}
]
}
}
]
@@ -0,0 +1,24 @@
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 = {
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
}
function initialize() {
}
}
@@ -0,0 +1,87 @@
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 = {
messageReceived: messageReceived,
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
}
function initialize() {
}
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)
}
}
}
}
@@ -0,0 +1,89 @@
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
}
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)
function onConnectionOpened(socket)
/*
This function is executed every time a new Websockets connection
is stablished.
*/ {
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.CLIENT_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 = {
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
console.log('Desktop Web App Discoonnected from Web Sockets Interface ................... Disonnected from port ' + global.env.CLIENT_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))
}
}
@@ -0,0 +1,93 @@
exports.newDesktopModulesHttpInterface = function newDesktopModulesHttpInterface() {
/*
This module represent the HTTP API of the
Desktop App. All HTTP request are processed
by this module.
*/
let thisObject = {
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
}
function initialize() {
/*
We will create an HTTP Server and leave it running forever.
*/
SA.nodeModules.http.createServer(onHttpRequest).listen(global.env.DESKTOP_HTTP_INTERFACE_PORT)
/* Starting the browser now is optional */
if (process.argv.includes("noBrowser")) {
//Running Client only with no UI.
} else {
SA.nodeModules.open('http://localhost:' + global.env.DESKTOP_HTTP_INTERFACE_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 '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)
}
}
}
@@ -0,0 +1,20 @@
exports.newSocialTradingModulesSocialGraph = function newSocialTradingModulesSocialGraph() {
/*
This object represent the entire Social Graph.
*/
let thisObject = {
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
}
function initialize() {
}
}
@@ -0,0 +1,98 @@
function newSocialTradingModulesWebSocketsClient() {
let thisObject = {
sendMessage: sendMessage,
initialize: initialize,
finalize: finalize
}
let socketClient
let called = {}
return thisObject
function finalize() {
socketClient.close()
socketClient = undefined
clientInterface = undefined
called = undefined
}
async function initialize() {
socketClient = new WebSocket('ws://' + UI.environment.DESKTOP_WEB_SOCKETS_INTERFACE_HOST + ':' + UI.environment.DESKTOP_WEB_SOCKETS_INTERFACE_PORT)
await setUpWebsocketClient()
}
async function setUpWebsocketClient() {
return new Promise(connectToNewtwork)
function connectToNewtwork(resolve, reject) {
try {
socketClient.onopen = () => { onConnection() }
socketClient.onerror = err => { onError(err) }
function onConnection() {
resolve()
}
function onError(err) {
console.log('[ERROR] Web Sockets Client -> onError -> err.message = ' + err.message)
console.log('[ERROR] Web Sockets Client -> onError -> err.stack = ' + err.stack)
}
} catch (err) {
console.log('[ERROR] Web Sockets Client -> setUpWebsocketClient -> err.stack = ' + err.stack)
}
}
}
function sendMessage(message) {
return new Promise(sendSocketMessage)
function sendSocketMessage(resolve, reject) {
if (socketClient.readyState !== 1) { // 1 means connected and ready.
console.log('[ERROR] Web Sockets Client -> sendMessage -> Cannot send message while connection is closed.')
reject('Websockets Connection Not Ready.')
return
}
let socketMessage = {
messageType: 'Request',
payload: message
}
socketClient.onmessage = socketMessage => { onMenssage(socketMessage) }
socketClient.send(
JSON.stringify(socketMessage)
)
function onMenssage(socketMessage) {
try {
let response = JSON.parse(socketMessage.data)
/*
Chack if we are waiting for the Handshake response.
*/
if (response.result === 'Ok') {
resolve(response.data)
} else {
console.log('[ERROR] Web Sockets Client -> onMenssage -> response.message = ' + response.message)
reject(response.message)
}
} catch (err) {
callbackFunction = undefined
console.log('[ERROR] Web Sockets Client -> err.stack = ' + err.stack)
}
}
}
}
}
+6 -3
View File
@@ -60,7 +60,10 @@ DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID = "baa2f02c-2920-4edb-a103-d452fc61d82f"
DK.TEST_NETWORK_CLIENT_USER_PROFILE_HANDLE = "Test-Network-Client-Profile"
DK.TEST_NETWORK_CLIENT_USER_PROFILE_PRIVATE_KEY = "0x5fed4817a87431c8a328d0936561e63f45b6db289adac6125b9306ded644dfe9"
DK.app = require('./Desktop/DesktopApp.js').newDesktopApp()
DK.app.run()
run()
console.log('Superalgos Desktop is Running.')
async function run() {
DK.app = require('./Desktop/DesktopApp.js').newDesktopApp()
await DK.app.run()
console.log('Superalgos Desktop App is Running!')
}