Desktop Websockets Internface Implemeted
This commit is contained in:
1 parent
44332a13de
commit
f3a7460985
7 files changed
+141
-8
No files matched your search
@@ -19,16 +19,13 @@ exports.newDesktopApp = function newDesktopApp() {
|
|||||||
await DK.webSocketsClient.initialize()
|
await DK.webSocketsClient.initialize()
|
||||||
|
|
||||||
/* These are the Network Interfaces by which the UI interacts with the Desktop App.*/
|
/* 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 = DK.projects.socialTrading.modules.webSocketsInterface.newDesktopModulesWebSocketsInterface()
|
||||||
WEB_SOCKETS_INTERFACE = WEB_SOCKETS_INTERFACE.newWebSocketsInterface()
|
|
||||||
WEB_SOCKETS_INTERFACE.initialize()
|
WEB_SOCKETS_INTERFACE.initialize()
|
||||||
console.log('Web Sockets Interface ....................................... Listening at port ' + global.env.CLIENT_WEB_SOCKETS_INTERFACE_PORT)
|
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()
|
HTTP_INTERFACE.initialize()
|
||||||
console.log('Http Interface .............................................. Listening at port ' + global.env.DESKTOP_HTTP_INTERFACE_PORT)
|
console.log('Http Interface .............................................. Listening at port ' + global.env.DESKTOP_HTTP_INTERFACE_PORT)
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ exports.newEnvironment = function () {
|
|||||||
WEB_SERVER_URL: 'localhost',
|
WEB_SERVER_URL: 'localhost',
|
||||||
CLIENT_WEB_SOCKETS_INTERFACE_PORT: 18041,
|
CLIENT_WEB_SOCKETS_INTERFACE_PORT: 18041,
|
||||||
NETWORK_WEB_SOCKETS_INTERFACE_PORT: 18042,
|
NETWORK_WEB_SOCKETS_INTERFACE_PORT: 18042,
|
||||||
|
DESKTOP_WEB_SOCKETS_INTERFACE_PORT: 18043,
|
||||||
CLIENT_HTTP_INTERFACE_PORT: 34248,
|
CLIENT_HTTP_INTERFACE_PORT: 34248,
|
||||||
DESKTOP_HTTP_INTERFACE_PORT: 34249,
|
DESKTOP_HTTP_INTERFACE_PORT: 34249,
|
||||||
PATH_TO_TASK_SERVER: './TaskServer',
|
PATH_TO_TASK_SERVER: './TaskServer',
|
||||||
|
|||||||
+1
-1
@@ -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 */
|
/* Set up Modules for this Project */
|
||||||
|
|||||||
@@ -1471,6 +1471,30 @@
|
|||||||
"fileName": "EventTypes.js"
|
"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": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
exports.newHttpInterface = function newHttpInterface() {
|
exports.newDesktopModulesHttpInterface = function newDesktopModulesHttpInterface() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This module represent the HTTP API of the
|
This module represent the HTTP API of the
|
||||||
Reference in new issue
Block a user