annotate web/collector/CollectorClient.ts @ 2422:62dc1b3644a0

collector client uses rdf types, not strings
author drewp@bigasterisk.com
date Tue, 21 May 2024 16:11:28 -0700
parents ae4b90efb55a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2417
diff changeset
1 import { Literal, NamedNode } from "n3";
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2417
diff changeset
2
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2417
diff changeset
3 type Settings = Array<[NamedNode,NamedNode,Literal]>;
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
4
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
5 export class CollectorClient {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
6 private settings: Settings;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
7 constructor(public clientName:string) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
8 this.settings = [];
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
9 this.putLoop();
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
10 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
11 private async putLoop() {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
12 await this.put();
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
13 setTimeout(() => {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
14 this.putLoop();
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
15 }, 1000);
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
16 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
17 private async put() {
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2417
diff changeset
18 // todo: WS
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
19 await fetch("/service/collector/attrs", {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
20 method: "PUT",
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
21 body: JSON.stringify({
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
22 client: this.clientName,
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
23 clientSession: "unused",
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
24 sendTime: Date.now() / 1000,
2422
62dc1b3644a0 collector client uses rdf types, not strings
drewp@bigasterisk.com
parents: 2417
diff changeset
25 settings: this.settings.map(([d,da,v]) => [d.value,da.value,v.value])
2417
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
26 }),
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
27 });
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
28 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
29 public async updateSettings(settings: Settings) {
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
30 this.settings = settings;
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
31 await this.put()
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
32 }
ae4b90efb55a start calibration tool
drewp@bigasterisk.com
parents:
diff changeset
33 }