Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8478b67

Browse files
committedOct 12, 2023
API change: record now contains ts and tsoff
1 parent ded4224 commit 8478b67

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed
 

‎js/activity-user.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
clearTimeout(PageRefresh);
2-
31
const pb = new PocketBase("https://api.xlx299.nz");
42
const coll = "activity";
53
const topic = "*";
6-
const staleSecs = 900;
4+
const stalemSecs = 900 * 1000;
75
var colors = {};
86

97
function removeStale() {
10-
let old = Date.now() - staleSecs * 1000;
8+
let old = Date.now() - stalemSecs;
119
let removed = false;
1210
$('li').each(function (i) {
1311
let ts = $(this).attr('data-ts');
@@ -16,17 +14,22 @@ function removeStale() {
1614
$(this).remove();
1715
// failsafe: if removed last li, nobody is transmitting
1816
if ($ul.find('li').length == 0) {
19-
$ul.parent().parent().fade("fast").hide("slow");
17+
$ul.parent().parent().hide("slow");
2018
}
2119
}
2220
});
21+
pb.health.check().then(function (result) {
22+
console.log('healthy');
23+
}).catch(function (err) {
24+
console.log('ill', err);
25+
});
2326
}
2427

25-
function activity(call, module, ts, duration) {
28+
function activity(call, module, ts, tsoff, duration) {
2629
duration = duration || 0;
2730
$('#mod-' + module).show("slow");
2831
//$('#mod-' + module).css('background-color', call ? 'salmon' : colors[module]);
29-
if (call) {
32+
if (call && (tsoff == 0)) {
3033
let $ul = $('#act-' + module);
3134
// if first li is the same call, all that is really
3235
// required is cancel animation and update ts
@@ -49,9 +52,10 @@ function activity(call, module, ts, duration) {
4952

5053
async function doRecent() {
5154
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}` });
5356
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);
5559
}
5660
}
5761

@@ -64,13 +68,15 @@ function saveColors() {
6468

6569
function subscribe() {
6670
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);
6975
}
70-
});
71-
/*.catch((error) => {
76+
}).catch((error) => {
77+
console.log('subscription error');
7278
console.error(error);
73-
}); */
79+
});
7480
}
7581

7682
var waitForJQuery = setInterval(function () {

‎js/activity.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ clearTimeout(PageRefresh);
33
const pb = new PocketBase("https://api.xlx299.nz");
44
const coll = "activity";
55
const topic = "*";
6-
const staleSecs = 900;
6+
const stalemSecs = 900 * 1000;
77
var colors = {};
88

99
function removeStale() {
10-
let old = Date.now() - staleSecs * 1000;
10+
let old = Date.now() - stalemSecs;
1111
let removed = false;
1212
$('li').each(function (i) {
1313
let ts = $(this).attr('data-ts');
@@ -24,10 +24,11 @@ function removeStale() {
2424
});
2525
}
2626

27-
function activity(call, module, ts, duration) {
27+
function activity(call, module, ts, tsoff, duration) {
2828
duration = duration || 0;
29-
$('#mod-' + module).css('background-color', call ? 'salmon' : colors[module]);
30-
if (call) {
29+
let onair = call && (tsoff == 0);
30+
$('#mod-' + module).css('background-color', onair ? 'salmon' : colors[module]);
31+
if (onair) {
3132
let $ul = $('#act-' + module);
3233
// if first li is the same call, all that is really
3334
// required is cancel animation and update ts
@@ -49,12 +50,11 @@ function activity(call, module, ts, duration) {
4950
}
5051

5152
async function doRecent() {
52-
console.log('Recent');
5353
let result = await pb.collection(coll).getFullList(400,
54-
{ filter: `system = "299" && ts >= ${Date.now() - staleSecs * 1000}` });
54+
{ filter: `system = "299" && ts >= ${Date.now() - stalemSecs}` });
5555
for (let row of result) {
56-
console.log(row.call, row.module, row.ts);
57-
activity(row.call, row.module, row.ts, 0);
56+
activity(row.call, row.module, row.ts, 0, 0);
57+
activity(row.call, row.module, row.ts, row.tsoff, 0);
5858
}
5959
}
6060

@@ -68,9 +68,10 @@ function saveColors() {
6868
function subscribe() {
6969
console.log(`Subscribing to ${topic} on ${coll}`);
7070
pb.collection(coll).subscribe(topic, function (e) {
71-
console.log(e.record.module, e.record.call, e);
72-
if (e.record.system == "299") {
73-
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);
7475
}
7576
});
7677
/*.catch((error) => {

0 commit comments

Comments
 (0)
Please sign in to comment.