Bug Fixed: Connection lost to Web Socket Server
This commit is contained in:
1 parent
a9a82ba854
commit
6cca8342ed
2 files changed
+22
-1
No files matched your search
@@ -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)
|
||||
|
||||
+18
-1
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user