Improvement on Socket Connection Error

This commit is contained in:
Luis Fernando Molina committed 2020-08-23 09:39:06 +02:00
1 parent eda2b14064
commit c17a655b1b
2 files changed
+47 -7

No files matched your search

+24 -2
View File
@@ -1,5 +1,5 @@
function newEventsServerClient(host, port, hostName) {
function newEventsServerClient(host, port, hostName, networkNode) {
/* Web Sockets Connection */
const MODULE_NAME = 'System Event Handler'
@@ -17,6 +17,7 @@ function newEventsServerClient(host, port, hostName) {
let thisObject = {
isConnected: isConnected,
initialize: initialize,
finalize: finalize,
physics: physics,
createEventHandler: createEventHandler,
deleteEventHandler: deleteEventHandler,
@@ -37,6 +38,21 @@ function newEventsServerClient(host, port, hostName) {
setuptWebSockets(callBackFunction)
}
function finalize() {
WEB_SOCKETS_CONNECTION.close()
WEB_SOCKETS_CONNECTION.onerror = undefined
WEB_SOCKETS_CONNECTION.onmessage = undefined
WEB_SOCKETS_CONNECTION.onopen = undefined
WEB_SOCKETS_CONNECTION = undefined
eventListeners = undefined
responseWaiters = undefined
commandsWaitingConfirmation = undefined
commandsSentByTimestamp = undefined
nonce = undefined
thisObject = undefined
}
function isConnected() {
if (WEB_SOCKETS_CONNECTION.readyState === 1) {
return true
@@ -156,7 +172,13 @@ function newEventsServerClient(host, port, hostName) {
}
if (thisObject.isConnected() !== true) {
canvas.cockpitSpace.setStatus('Connecting to Superalgos Backend at ' + hostName + ' Network Node. Please wait until the connection is established.', 100, canvas.cockpitSpace.statusTypes.WARNING)
if (networkNode !== undefined) {
if (networkNode.payload !== undefined) {
if (networkNode.payload.uiObject !== undefined) {
networkNode.payload.uiObject.setErrorMessage('Connecting to Superalgos Backend at ' + hostName + ' Network Node')
}
}
}
} else {
retryCommandsPhysics()
}