1
- clearTimeout ( PageRefresh ) ;
2
-
3
1
const pb = new PocketBase ( "https://api.xlx299.nz" ) ;
4
2
const coll = "activity" ;
5
3
const topic = "*" ;
6
- const staleSecs = 900 ;
4
+ const stalemSecs = 900 * 1000 ;
7
5
var colors = { } ;
8
6
9
7
function removeStale ( ) {
10
- let old = Date . now ( ) - staleSecs * 1000 ;
8
+ let old = Date . now ( ) - stalemSecs ;
11
9
let removed = false ;
12
10
$ ( 'li' ) . each ( function ( i ) {
13
11
let ts = $ ( this ) . attr ( 'data-ts' ) ;
@@ -16,17 +14,22 @@ function removeStale() {
16
14
$ ( this ) . remove ( ) ;
17
15
// failsafe: if removed last li, nobody is transmitting
18
16
if ( $ul . find ( 'li' ) . length == 0 ) {
19
- $ul . parent ( ) . parent ( ) . fade ( "fast" ) . hide ( "slow" ) ;
17
+ $ul . parent ( ) . parent ( ) . hide ( "slow" ) ;
20
18
}
21
19
}
22
20
} ) ;
21
+ pb . health . check ( ) . then ( function ( result ) {
22
+ console . log ( 'healthy' ) ;
23
+ } ) . catch ( function ( err ) {
24
+ console . log ( 'ill' , err ) ;
25
+ } ) ;
23
26
}
24
27
25
- function activity ( call , module , ts , duration ) {
28
+ function activity ( call , module , ts , tsoff , duration ) {
26
29
duration = duration || 0 ;
27
30
$ ( '#mod-' + module ) . show ( "slow" ) ;
28
31
//$('#mod-' + module).css('background-color', call ? 'salmon' : colors[module]);
29
- if ( call ) {
32
+ if ( call && ( tsoff == 0 ) ) {
30
33
let $ul = $ ( '#act-' + module ) ;
31
34
// if first li is the same call, all that is really
32
35
// required is cancel animation and update ts
@@ -49,9 +52,10 @@ function activity(call, module, ts, duration) {
49
52
50
53
async function doRecent ( ) {
51
54
let result = await pb . collection ( coll ) . getFullList ( 400 ,
52
- { filter : `system = "299" && ts >= ${ Date . now ( ) - staleSecs * 1000 } ` } ) ;
55
+ { filter : `system = "299" && ts >= ${ Date . now ( ) - stalemSecs } ` } ) ;
53
56
for ( let row of result ) {
54
- activity ( row . call , row . module , row . ts , 0 ) ;
57
+ activity ( row . call , row . module , row . ts , 0 , 0 ) ;
58
+ activity ( row . call , row . module , row . ts , row . tsoff , 0 ) ;
55
59
}
56
60
}
57
61
@@ -64,13 +68,15 @@ function saveColors() {
64
68
65
69
function subscribe ( ) {
66
70
pb . collection ( coll ) . subscribe ( topic , function ( e ) {
67
- if ( e . record . system == "299" ) {
68
- activity ( e . record . call , e . record . module , e . record . ts , 400 ) ;
71
+ let old = Date . now ( ) - stalemSecs ;
72
+ if ( ( e . record . system == "299" ) && ( e . record . ts > old ) ) {
73
+ activity ( e . record . call , e . record . module , e . record . ts ,
74
+ e . record . tsoff , 400 ) ;
69
75
}
70
- } ) ;
71
- /*.catch(( error) => {
76
+ } ) . catch ( ( error ) => {
77
+ console . log ( 'subscription error' ) ;
72
78
console . error ( error ) ;
73
- }); */
79
+ } ) ;
74
80
}
75
81
76
82
var waitForJQuery = setInterval ( function ( ) {
0 commit comments