Websockets Client Bug Fixed, that prevented concurrent messages.
This commit is contained in:
1 parent
e351fe271f
commit
44033decc6
7 files changed
+55
-22
No files matched your search
@@ -47,11 +47,16 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule
|
||||
queryMessage.emitterUserProfileId = DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID
|
||||
messageHeader.queryMessage = JSON.stringify(queryMessage)
|
||||
|
||||
console.log((new Date()).toISOString(), '- Web App Interface', '- Query Message Received', JSON.stringify(queryMessage))
|
||||
|
||||
let response = {
|
||||
result: 'Ok',
|
||||
message: 'Web App Interface Query Processed.',
|
||||
data: await DK.running.webSocketsClient.sendMessage(JSON.stringify(messageHeader))
|
||||
}
|
||||
|
||||
console.log((new Date()).toISOString(), '- Web App Interface', '- Query Respose Sent', JSON.stringify(response))
|
||||
|
||||
return response
|
||||
}
|
||||
case 'Event': {
|
||||
@@ -131,7 +136,7 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule
|
||||
const fileHash = hash.update(fileContent).digest('hex')
|
||||
const fileName = fileHash + ".json"
|
||||
|
||||
let filePath = './My-Social-Trading-Data/User-Posts/' + SA.projects.foundations.utilities.filesAndDirectories.pathFromDate(timestamp)
|
||||
let filePath = './My-Social-Trading-Data/User-Posts/' + SA.projects.foundations.utilities.filesAndDirectories.pathFromDate(timestamp)
|
||||
|
||||
SA.projects.foundations.utilities.filesAndDirectories.mkDirByPathSync(filePath + '/')
|
||||
SA.nodeModules.fs.writeFileSync(filePath + '/' + fileName, fileContent)
|
||||
|
||||
@@ -57,6 +57,7 @@ exports.newDesktopModulesWebSocketsInterface = function newDesktopModulesWebSock
|
||||
messageHeader = JSON.parse(message)
|
||||
} catch (err) {
|
||||
let response = {
|
||||
messageId: messageHeader.messageId,
|
||||
result: 'Error',
|
||||
message: 'messageHeader Not Coorrect JSON Format.'
|
||||
}
|
||||
@@ -69,12 +70,14 @@ exports.newDesktopModulesWebSocketsInterface = function newDesktopModulesWebSock
|
||||
.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
|
||||
}
|
||||
|
||||
@@ -207,11 +207,16 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule
|
||||
let query = NT.projects.socialTrading.modules.query.newSocialTradingModulesQuery()
|
||||
query.initialize(queryReceived)
|
||||
|
||||
console.log((new Date()).toISOString(), '- Client Interface', '- Query Message Received', queryMessage)
|
||||
|
||||
let response = {
|
||||
result: 'Ok',
|
||||
message: 'Client Interface Query Processed.',
|
||||
data: query.execute()
|
||||
}
|
||||
|
||||
console.log((new Date()).toISOString(), '- Client Interface', '- Query Respose Sent', JSON.stringify(response))
|
||||
|
||||
return response
|
||||
|
||||
} catch (err) {
|
||||
|
||||
@@ -9,6 +9,7 @@ function newSocialTradingModulesWebSocketsClient() {
|
||||
let socketClient
|
||||
|
||||
let called = {}
|
||||
let onMessageFunctionsMap = new Map()
|
||||
|
||||
return thisObject
|
||||
|
||||
@@ -18,6 +19,7 @@ function newSocialTradingModulesWebSocketsClient() {
|
||||
clientInterface = undefined
|
||||
|
||||
called = undefined
|
||||
onMessageFunctionsMap = undefined
|
||||
}
|
||||
|
||||
async function initialize() {
|
||||
@@ -38,6 +40,7 @@ function newSocialTradingModulesWebSocketsClient() {
|
||||
socketClient.onerror = err => { onError(err) }
|
||||
|
||||
function onConnection() {
|
||||
socketClient.onmessage = socketMessage => { onMenssage(socketMessage) }
|
||||
resolve()
|
||||
}
|
||||
|
||||
@@ -65,22 +68,17 @@ function newSocialTradingModulesWebSocketsClient() {
|
||||
}
|
||||
|
||||
let socketMessage = {
|
||||
messageId: SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId(),
|
||||
messageType: 'Request',
|
||||
payload: message
|
||||
}
|
||||
socketClient.onmessage = socketMessage => { onMenssage(socketMessage) }
|
||||
onMessageFunctionsMap.set(socketMessage.messageId, onMenssageFunction)
|
||||
socketClient.send(
|
||||
JSON.stringify(socketMessage)
|
||||
)
|
||||
)
|
||||
|
||||
function onMenssage(socketMessage) {
|
||||
function onMenssageFunction(response) {
|
||||
try {
|
||||
|
||||
let response = JSON.parse(socketMessage.data)
|
||||
/*
|
||||
Chack if we are waiting for the Handshake response.
|
||||
*/
|
||||
|
||||
if (response.result === 'Ok') {
|
||||
resolve(response.data)
|
||||
} else {
|
||||
@@ -95,4 +93,15 @@ function newSocialTradingModulesWebSocketsClient() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onMenssage(socketMessage) {
|
||||
|
||||
let response = JSON.parse(socketMessage.data)
|
||||
/*
|
||||
We get the functioin that is going to resolve or reject the promise given.
|
||||
*/
|
||||
onMenssageFunction = onMessageFunctionsMap.get(response.messageId)
|
||||
onMessageFunctionsMap.delete(response.messageId)
|
||||
onMenssageFunction(response)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user