Skip to content

Commit 13a4f7d

Browse files
committed
better practices
1 parent b9976ee commit 13a4f7d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

services/static-webserver/client/source/class/osparc/Application.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,13 @@ qx.Class.define("osparc.Application", {
506506
this.__mainPage = mainPage;
507507
this.__loadView(mainPage);
508508
};
509-
if (osparc.wrapper.WebSocket.getInstance().isAppConnected()) {
509+
const wsInstance = osparc.wrapper.WebSocket.getInstance();
510+
if (wsInstance.isAppConnected()) {
510511
loadViewerPage();
511512
} else {
512-
osparc.wrapper.WebSocket.getInstance().addListener("changeAppConnected", e => {
513+
const listenerId = wsInstance.addListener("changeAppConnected", function(e) {
513514
if (e.getData()) {
515+
wsInstance.removeListenerById(listenerId);
514516
loadViewerPage();
515517
}
516518
}, this);
@@ -528,11 +530,13 @@ qx.Class.define("osparc.Application", {
528530
this.__mainPage = mainPage;
529531
this.__loadView(mainPage);
530532
};
531-
if (osparc.wrapper.WebSocket.getInstance().isAppConnected()) {
533+
const wsInstance = osparc.wrapper.WebSocket.getInstance();
534+
if (wsInstance.isAppConnected()) {
532535
loadNodeViewerPage();
533536
} else {
534-
osparc.wrapper.WebSocket.getInstance().addListener("changeAppConnected", e => {
537+
const listenerId = wsInstance.addListener("changeAppConnected", e => {
535538
if (e.getData()) {
539+
wsInstance.removeListenerById(listenerId);
536540
loadNodeViewerPage();
537541
}
538542
}, this);

services/static-webserver/client/source/class/osparc/WatchDog.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ qx.Class.define("osparc.WatchDog", {
6868
},
6969
},
7070

71+
statics: {
72+
DEFAULT_HEARTBEAT_INTERVAL: 2000, // default to 2 seconds
73+
},
74+
7175
members: {
7276
__clientHeartbeatWWPinger: null,
7377

@@ -89,7 +93,7 @@ qx.Class.define("osparc.WatchDog", {
8993
},
9094

9195
__startPinging: function() {
92-
const heartbeatInterval = this.getHeartbeatInterval() || 2000; // default to 2 seconds
96+
const heartbeatInterval = this.getHeartbeatInterval() || osparc.WatchDog.DEFAULT_HEARTBEAT_INTERVAL;
9397
this.__clientHeartbeatWWPinger.postMessage(["start", heartbeatInterval]);
9498
},
9599

0 commit comments

Comments
 (0)