pi-tps-web 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.html CHANGED
@@ -16,7 +16,7 @@
16
16
  }
17
17
  })();
18
18
  </script>
19
- <script type="module" crossorigin src="/assets/index-BwpWPmjQ.js"></script>
19
+ <script type="module" crossorigin src="/assets/index-X3Vcf92M.js"></script>
20
20
  <link rel="stylesheet" crossorigin href="/assets/index-DRtHH789.css">
21
21
  </head>
22
22
  <body>
@@ -142,6 +142,9 @@ export default function tpsWebExtension(pi: ExtensionAPI) {
142
142
  let telemetryJsonl: string | null = null;
143
143
  let telemetryVersion = 0;
144
144
 
145
+ // Connected SSE clients for real-time push notifications.
146
+ const sseClients = new Set<import('http').ServerResponse>();
147
+
145
148
  function startServer(): Promise<number> {
146
149
  if (server) return Promise.resolve(serverPort);
147
150
 
@@ -171,6 +174,24 @@ export default function tpsWebExtension(pi: ExtensionAPI) {
171
174
  return;
172
175
  }
173
176
 
177
+ // API: Server-Sent Events stream for real-time push.
178
+ // When /tps-web updates the telemetry, the server pushes
179
+ // the new version to all connected clients immediately,
180
+ // eliminating the 2s polling latency.
181
+ if (urlPath === '/api/events') {
182
+ res.writeHead(200, {
183
+ 'Content-Type': 'text/event-stream',
184
+ 'Cache-Control': 'no-store',
185
+ 'Connection': 'keep-alive',
186
+ });
187
+ res.write('');
188
+ sseClients.add(res);
189
+ req.on('close', () => {
190
+ sseClients.delete(res);
191
+ });
192
+ return;
193
+ }
194
+
174
195
  // Static files from dist/
175
196
  serveStatic(DIST_PATH, req, res);
176
197
  });
@@ -194,6 +215,11 @@ export default function tpsWebExtension(pi: ExtensionAPI) {
194
215
 
195
216
  // Clean up server on session shutdown
196
217
  pi.on('session_shutdown', () => {
218
+ // Close all SSE connections before shutting down the server
219
+ for (const client of sseClients) {
220
+ client.end();
221
+ }
222
+ sseClients.clear();
197
223
  if (server) {
198
224
  server.close();
199
225
  server = null;
@@ -297,6 +323,11 @@ export default function tpsWebExtension(pi: ExtensionAPI) {
297
323
  telemetryJsonl = content;
298
324
  telemetryVersion++;
299
325
 
326
+ // Push update to all connected SSE clients
327
+ for (const client of sseClients) {
328
+ client.write(`data: ${JSON.stringify({ version: telemetryVersion })}\n\n`);
329
+ }
330
+
300
331
  const structuralCount = exportedEntries.filter((e: { type: string }) => isStructural(e)).length;
301
332
  const customCount = exportedEntries.length - structuralCount;
302
333
  const parts: string[] = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-tps-web",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",