Add handoff task document for PWA, chats, and connections

This commit is contained in:
ai5590
2026-04-05 12:13:05 +03:00
parent cf5460c5c7
commit bc8f4a0582
46 changed files with 1671 additions and 106 deletions
+29 -1
View File
@@ -21,6 +21,7 @@ export class WsJsonClient {
this.ws = null;
this.pending = new Map();
this.openPromise = null;
this.eventListeners = new Map();
}
async open() {
@@ -53,6 +54,7 @@ export class WsJsonClient {
});
}).finally(() => {
this.openPromise = null;
this.eventListeners = new Map();
});
return this.openPromise;
@@ -116,14 +118,40 @@ export class WsJsonClient {
}
const requestId = data?.requestId;
if (!requestId) return;
const isEvent = data?.event === true || (requestId && !this.pending.has(requestId));
if (isEvent) {
this.emitEvent(data?.op || '', data);
return;
}
if (!requestId) return;
const slot = this.pending.get(requestId);
if (!slot) return;
this.pending.delete(requestId);
slot.resolve(data);
}
onEvent(op, callback) {
if (!op || typeof callback !== 'function') return () => {};
if (!this.eventListeners.has(op)) {
this.eventListeners.set(op, new Set());
}
const set = this.eventListeners.get(op);
set.add(callback);
return () => {
set.delete(callback);
if (!set.size) this.eventListeners.delete(op);
};
}
emitEvent(op, data) {
const listeners = this.eventListeners.get(op);
if (!listeners) return;
listeners.forEach((cb) => {
try { cb(data); } catch {}
});
}
failPending(message) {
const pendingOps = [...this.pending.values()]
.map((slot) => slot.op)