1515
1616************************************************************************ */
1717
18+ /**
19+ * @asset (pacemaker.js)
20+ * @ignore (Worker)
21+ */
22+
1823/**
1924 * Singleton class that does some network connection checks.
2025 *
3338
3439qx . Class . define ( "osparc.io.WatchDog" , {
3540 extend : qx . core . Object ,
36-
37- type : "singleton" ,
41+ type : "singleton" ,
3842
3943 construct : function ( ) {
40- this . __clientHeartbeatPinger = new qx . event . Timer ( this . heartbeatInterval ) ;
41- this . __clientHeartbeatPinger . addListener ( "interval" , function ( ) {
42- const socket = osparc . wrapper . WebSocket . getInstance ( ) ;
43- try {
44- socket . emit ( "client_heartbeat" ) ;
45- } catch ( error ) {
46- // no need to handle the error, nor does it need to cause further issues
47- // it is ok to eat it up
48- }
49- } , this ) ;
44+ this . __clientHeartbeatWWPinger = new Worker ( "resource/osparc/pacemaker.js" ) ;
45+ this . __clientHeartbeatWWPinger . onmessage = ( ) => {
46+ this . __pingServer ( ) ;
47+ } ;
5048
5149 // register for socket.io event to change the default heartbeat interval
5250 const socket = osparc . wrapper . WebSocket . getInstance ( ) ;
5351 const socketIoEventName = "set_heartbeat_emit_interval" ;
5452 socket . removeSlot ( socketIoEventName ) ;
55- socket . on ( socketIoEventName , function ( emitIntervalSeconds ) {
56- this . setHeartbeatInterval ( parseInt ( emitIntervalSeconds ) * 1000 ) ;
53+ socket . on ( socketIoEventName , emitIntervalSeconds => {
54+ const newInterval = parseInt ( emitIntervalSeconds ) * 1000 ;
55+ this . setHeartbeatInterval ( newInterval ) ;
5756 } , this ) ;
5857 } ,
5958
@@ -74,18 +73,33 @@ qx.Class.define("osparc.io.WatchDog", {
7473 } ,
7574
7675 members : {
77- __clientHeartbeatPinger : null ,
76+ __clientHeartbeatWWPinger : null ,
7877
7978 _applyOnLine : function ( value ) {
8079 let logo = osparc . component . widget . LogoOnOff . getInstance ( ) ;
8180 if ( logo ) {
8281 logo . setOnLine ( value ) ;
8382 }
84- value ? this . __clientHeartbeatPinger . start ( ) : this . __clientHeartbeatPinger . stop ( ) ;
83+
84+ if ( value ) {
85+ this . __clientHeartbeatWWPinger . postMessage ( [ "start" , this . getHeartbeatInterval ( ) ] ) ;
86+ } else {
87+ this . __clientHeartbeatWWPinger . postMessage ( [ "stop" ] ) ;
88+ }
8589 } ,
8690
8791 _applyHeartbeatInterval : function ( value ) {
88- this . __clientHeartbeatPinger . setInterval ( value ) ;
92+ this . __clientHeartbeatWWPinger . postMessage ( [ "start" , value ] ) ;
93+ } ,
94+
95+ __pingServer : function ( ) {
96+ const socket = osparc . wrapper . WebSocket . getInstance ( ) ;
97+ try {
98+ socket . emit ( "client_heartbeat" ) ;
99+ } catch ( error ) {
100+ // no need to handle the error, nor does it need to cause further issues
101+ // it is ok to eat it up
102+ }
89103 }
90- } // members
104+ }
91105} ) ;
0 commit comments