expose Ignis API, implement shared ws client

This commit is contained in:
Nystik
2026-05-24 21:51:02 +02:00
parent 9eeff3c1b3
commit 28effab1ed
29 changed files with 824 additions and 745 deletions

View File

@@ -2,57 +2,26 @@ const CHANNEL = "plugin:headless-sync";
class SyncBroadcaster {
constructor(wss) {
this._wss = wss;
this._logSubscriptions = new Map();
}
subscribeToLogs(vaultId) {
this._logSubscriptions.set(vaultId, { expires: Date.now() + 10000 });
this._channel = wss.channel(CHANNEL);
}
broadcastLog(vaultId, line) {
if (!this._wss?.clients) {
return;
}
const sub = this._logSubscriptions.get(vaultId);
if (!sub || Date.now() > sub.expires) {
return;
}
this._send({
channel: CHANNEL,
this._channel.broadcastToVault(vaultId, {
type: "sync-log",
payload: { vaultId, line },
});
}
broadcastStatus(state) {
if (!state) {
if (!state || !state.vaultId) {
return;
}
this._send({
channel: CHANNEL,
this._channel.broadcastToVault(state.vaultId, {
type: "sync-status",
payload: state,
});
}
_send(msg) {
if (!this._wss?.clients) {
return;
}
const data = JSON.stringify(msg);
for (const client of this._wss.clients) {
if (client.readyState === 1) {
client.send(data);
}
}
}
}
module.exports = { SyncBroadcaster };