diff --git a/Canvas.js b/Canvas.js index 9da5ed793..843b27b8d 100644 --- a/Canvas.js +++ b/Canvas.js @@ -118,13 +118,17 @@ function newCanvas () { animation.initialize() thisObject.animation = animation + /* Low Level Infraestructure First */ + animation.addCallBackFunction('System Event Handler Physics', systemEventHandler.physics) + /* Spcaces Physics */ animation.addCallBackFunction('Floating Space Physics', thisObject.floatingSpace.physics) animation.addCallBackFunction('Chart Space Physics', thisObject.chartSpace.physics) animation.addCallBackFunction('CockpitSpace Physics', thisObject.cockpitSpace.physics) animation.addCallBackFunction('Strategy Space Physics', thisObject.strategySpace.physics) animation.addCallBackFunction('Panels Space Physics', thisObject.panelsSpace.physics) + /* Spcaces Drawing */ animation.addCallBackFunction('Floating Space Draw', thisObject.floatingSpace.draw) animation.addCallBackFunction('Chart Space Background', thisObject.chartSpace.drawBackground) animation.addCallBackFunction('Chart Space Draw', thisObject.chartSpace.draw) diff --git a/SystemEventHandler.js b/SystemEventHandler.js index 740048d48..c41604552 100644 --- a/SystemEventHandler.js +++ b/SystemEventHandler.js @@ -4,6 +4,7 @@ function newSystemEventHandler () { const MODULE_NAME = 'System Event Handler' const ERROR_LOG = true + const INFO_LOG = true const logger = newWebDebugLog() logger.fileName = MODULE_NAME @@ -12,6 +13,7 @@ function newSystemEventHandler () { let thisObject = { initialize: initialize, + physics: physics, createEventHandler: createEventHandler, deleteEventHandler: deleteEventHandler, listenToEvent: listenToEvent, @@ -95,6 +97,15 @@ function newSystemEventHandler () { sendCommand(eventCommand, responseCallBack) } + function physics () { + if (WEB_SOCKETS_CONNECTION !== undefined) { + if (WEB_SOCKETS_CONNECTION.readyState === 3) { // Connection closed. May happen after computer goes to sleep. + setuptWebSockets() + if (INFO_LOG === true) { logger.write('[INFO] setuptWebSockets -> Found Web Sockets Connection Closed. Reconnected to WebSockets Server.') } + } + } + } + function setuptWebSockets (callBackFunction) { try { WEB_SOCKETS_CONNECTION = new WebSocket(WEB_SOCKETS_URL) @@ -105,7 +116,13 @@ function newSystemEventHandler () { console.log('WebSocket error:' + JSON.stringify(error)) } WEB_SOCKETS_CONNECTION.onopen = () => { - callBackFunction() + if (callBackFunction !== undefined) { + callBackFunction() + } + } + WEB_SOCKETS_CONNECTION.onclose = () => { + setTimeout(setuptWebSockets, 1000) + if (INFO_LOG === true) { logger.write('[INFO] setuptWebSockets -> Web Sockets Connection was Closed. Reconnected to WebSockets Server. ') } } WEB_SOCKETS_CONNECTION.onmessage = e => { // console.log('Websoked Message Received: ' + e.data)