Improvement on Socket Connection Error
This commit is contained in:
1 parent
eda2b14064
commit
c17a655b1b
2 files changed
+47
-7
No files matched your search
@@ -67,6 +67,7 @@ function newWorkspace() {
|
||||
|
||||
thisObject.nodeChildren = newNodeChildren()
|
||||
|
||||
let savingWorkspaceIntervalId
|
||||
let isInitialized = false
|
||||
let workingAtTask = 0
|
||||
let circularProgressBar = newBusyProgressBar()
|
||||
@@ -118,7 +119,7 @@ function newWorkspace() {
|
||||
thisObject.enabled = true
|
||||
canvas.cockpitSpace.initializePosition()
|
||||
canvas.splashScreen.initialize()
|
||||
setInterval(saveWorkspace, 60000)
|
||||
savingWorkspaceIntervalId = setInterval(saveWorkspace, 60000)
|
||||
isInitialized = true
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -162,7 +163,7 @@ function newWorkspace() {
|
||||
if (host === undefined) { host = 'localhost' }
|
||||
if (webSocketsPort === undefined) { webSocketsPort = '8080' }
|
||||
|
||||
let eventsServerClient = newEventsServerClient(host, webSocketsPort, networkNode.name)
|
||||
let eventsServerClient = newEventsServerClient(host, webSocketsPort, networkNode.name, networkNode)
|
||||
eventsServerClient.initialize()
|
||||
|
||||
thisObject.eventsServerClients.set(networkNode.id, eventsServerClient)
|
||||
@@ -233,6 +234,14 @@ function newWorkspace() {
|
||||
}
|
||||
}
|
||||
|
||||
function finalizeEventsServerClients() {
|
||||
thisObject.eventsServerClients.forEach(finalize)
|
||||
|
||||
function finalize(eventServerClient) {
|
||||
eventServerClient.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
function replacingWorkspacePhysics() {
|
||||
if (thisObject.enabled !== true) { return }
|
||||
|
||||
@@ -249,21 +258,30 @@ function newWorkspace() {
|
||||
workingAtTask++
|
||||
break
|
||||
case 3:
|
||||
finalizeEventsServerClients()
|
||||
thisObject.eventsServerClients = new Map()
|
||||
workingAtTask++
|
||||
break
|
||||
case 4:
|
||||
clearInterval(savingWorkspaceIntervalId)
|
||||
workingAtTask++
|
||||
break
|
||||
case 5:
|
||||
thisObject.workspaceNode = loadedWorkspaceNode
|
||||
loadedWorkspaceNode = undefined
|
||||
workingAtTask++
|
||||
break
|
||||
case 4:
|
||||
case 6:
|
||||
functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode)
|
||||
setupEventsServerClients()
|
||||
runTasksAndSessions(true)
|
||||
workingAtTask++
|
||||
break
|
||||
case 5:
|
||||
case 7:
|
||||
canvas.chartingSpace.reset()
|
||||
workingAtTask++
|
||||
break
|
||||
case 6:
|
||||
case 8:
|
||||
workingAtTask = 0
|
||||
circularProgressBar.visible = false
|
||||
break
|
||||
|
||||
+24
-2
@@ -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()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user