Event received from browser to browser going through 1 network node

This commit is contained in:
Luis Fernando Molina committed 2021-11-10 12:44:50 +01:00
1 parent 578f36eceb
commit c5564f1e69
5 files changed
+21 -23

No files matched your search

-1
View File
@@ -5,7 +5,6 @@ exports.newDesktopApp = function newDesktopApp() {
p2pNetworkClient: undefined, p2pNetworkClient: undefined,
p2pNetwork: undefined, p2pNetwork: undefined,
p2pNetworkPeers: undefined, p2pNetworkPeers: undefined,
webSocketsClient: undefined,
webSocketsInterface: undefined, webSocketsInterface: undefined,
webAppInterface: undefined, webAppInterface: undefined,
p2pNetworkInterface: undefined, p2pNetworkInterface: undefined,
@@ -288,20 +288,20 @@ exports.newNetworkModulesWebSocketsNetworkClient = function newNetworkModulesWeb
} }
} }
function onMenssage(message) { function onMenssage(socketMessage) {
let response = JSON.parse(message.data) let message = JSON.parse(socketMessage.data)
/* /*
We get the function that is going to resolve or reject the promise given. We get the function that is going to resolve or reject the promise given.
*/ */
let onMenssageFunction = onMessageFunctionsMap.get(response.messageId) let onMenssageFunction = onMessageFunctionsMap.get(message.messageId)
if (onMenssageFunction !== undefined) { if (onMenssageFunction !== undefined) {
/* /*
The message received is a response to a message sent. The message received is a response to a message sent.
*/ */
onMessageFunctionsMap.delete(response.messageId) onMessageFunctionsMap.delete(message.messageId)
onMenssageFunction(response) onMenssageFunction(message)
} else { } else {
/* /*
The message received is a not response to a message sent. The message received is a not response to a message sent.
@@ -310,9 +310,9 @@ exports.newNetworkModulesWebSocketsNetworkClient = function newNetworkModulesWeb
This can only happen when this module is running at an APP like the Desktop App. This can only happen when this module is running at an APP like the Desktop App.
*/ */
let messageHeader let event
try { try {
messageHeader = JSON.parse(message) event = JSON.parse(message.eventMessage)
} catch (err) { } catch (err) {
console.log('[ERROR] Web Sockets Network Client -> onMenssage -> message = ' + message) console.log('[ERROR] Web Sockets Network Client -> onMenssage -> message = ' + message)
console.log('[ERROR] Web Sockets Network Client -> onMenssage -> err.stack = ' + err.stack) console.log('[ERROR] Web Sockets Network Client -> onMenssage -> err.stack = ' + err.stack)
@@ -320,7 +320,7 @@ exports.newNetworkModulesWebSocketsNetworkClient = function newNetworkModulesWeb
return return
} }
DK.desktopApp.p2pNetworkInterface.messageReceived(messageHeader.payload) DK.desktopApp.p2pNetworkInterface.eventReceived(event)
} }
} }
} }
@@ -7,7 +7,7 @@ exports.newSocialTradingModulesP2PNetworkInterface = function newSocialTradingMo
by the user running this app, in particular trading events. by the user running this app, in particular trading events.
*/ */
let thisObject = { let thisObject = {
messageReceived: messageReceived, eventReceived: eventReceived,
initialize: initialize, initialize: initialize,
finalize: finalize finalize: finalize
} }
@@ -22,8 +22,7 @@ exports.newSocialTradingModulesP2PNetworkInterface = function newSocialTradingMo
} }
async function messageReceived(message) { async function eventReceived(event) {
message.messageId = undefined DK.desktopApp.webSocketsInterface.sendToWebApp(JSON.stringify(event))
DK.webSocketsInterface.sendToWebApp(JSON.stringify(response))
} }
} }
@@ -132,7 +132,7 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule
let response = { let response = {
result: 'Ok', result: 'Ok',
message: 'Web App Interface Event Processed.', message: 'Web App Interface Event Processed.',
data: await DK.desktopApp.webSocketsClient.sendMessage(JSON.stringify(messageHeader)) data: await DK.desktopApp.p2pNetworkPeers.sendMessage(JSON.stringify(messageHeader))
} }
return response return response
} }
@@ -94,28 +94,28 @@ function newSocialTradingModulesWebSocketsWebAppClient() {
} }
} }
function onMenssage(message) { function onMenssage(socketMessage) {
let response = JSON.parse(message.data) let message = JSON.parse(socketMessage.data)
/* /*
We get the function that is going to resolve or reject the promise given. We get the function that is going to resolve or reject the promise given.
*/ */
onMenssageFunction = onMessageFunctionsMap.get(response.messageId) onMenssageFunction = onMessageFunctionsMap.get(message.messageId)
onMessageFunctionsMap.delete(response.messageId) onMessageFunctionsMap.delete(message.messageId)
if (onMenssageFunction !== undefined) { if (onMenssageFunction !== undefined) {
/* /*
The message received is a response to a message sent. The message received is a response to a message sent.
*/ */
onMenssageFunction(response) onMenssageFunction(message)
} else { } else {
/* /*
The message received is a not response to a message sent. The message received is a not response to a message sent.
That means that is a notification received from the Client App. That means that is an event received from the Client App.
*/ */
let messageHeader let event
try { try {
messageHeader = JSON.parse(message) event = JSON.parse(message)
} catch (err) { } catch (err) {
console.log('[ERROR] Web Sockets WebApp Client -> onMenssage -> message = ' + message) console.log('[ERROR] Web Sockets WebApp Client -> onMenssage -> message = ' + message)
console.log('[ERROR] Web Sockets WebApp Client -> onMenssage -> err.stack = ' + err.stack) console.log('[ERROR] Web Sockets WebApp Client -> onMenssage -> err.stack = ' + err.stack)
@@ -123,7 +123,7 @@ function newSocialTradingModulesWebSocketsWebAppClient() {
return return
} }
UI.webApp.messageReceived(messageHeader.payload) UI.webApp.messageReceived(JSON.stringify(event))
} }
} }
} }