diff web/collector/Light9CollectorUi.ts @ 2395:ef3cde3e81e8

switch collector output from json to avro (still over WS)
author drewp@bigasterisk.com
date Thu, 16 May 2024 15:03:50 -0700
parents ffa2f340ffdf
children
line wrap: on
line diff
--- a/web/collector/Light9CollectorUi.ts	Tue May 14 14:46:56 2024 -0700
+++ b/web/collector/Light9CollectorUi.ts	Thu May 16 15:03:50 2024 -0700
@@ -10,7 +10,7 @@
 import { Light9CollectorDevice } from "./Light9CollectorDevice";
 export { RdfdbSyncedGraph } from "../RdfdbSyncedGraph";
 export { Light9CollectorDevice };
-
+import { avro } from "../lib/avro";
 debug.enable("*");
 const log = debug("collector");
 
@@ -34,15 +34,21 @@
       this.graph.runHandler(this.findDevices.bind(this), "findDevices");
     });
 
-    const ws = new ReconnectingWebSocket("ws://localhost:8200/service/collector/updates");
-    ws.addEventListener("message", (ev: any) => {
-      const outputAttrsSet = JSON.parse(ev.data).outputAttrsSet;
+    this.setupListener();
+  }
+
+  async setupListener() {
+    const CollectorUpdateType = await avro.loadType("CollectorUpdate");
+    const ws = new ReconnectingWebSocket(`ws://${location.host}/service/collector/updates`);
+    ws.addEventListener("message", async (ev: ReconnectingWebSocket.MessageEvent) => {
+      const jsMsg = await avro.parseBlob(CollectorUpdateType, ev.data);
+
+      const outputAttrsSet = jsMsg.OutputAttrsSet;
       if (outputAttrsSet) {
         this.updateDev(outputAttrsSet.dev, outputAttrsSet.attrs);
       }
     });
   }
-
   findDevices(patch?: Patch) {
     const U = this.graph.U();