[0.9.1] FORK_IA_UX: Fase 2 cross-device — relay Karvan messages over SSB private msgs
Makes a Karvan room work between two different phones once they're connected to a pub: - karvan_model: rooms track remoteFeeds (SSB ids of other participants); addRemoteFeed/ getRemoteFeeds/anyRemoteRooms (feed-id validated, capped at MAX_MEMBERS). - backend: inviting registers the invitee's feed; joining by link registers the inviter's feed (read from the invite PM). Posting a message publishes a private 'karvan-relay' to those feeds; an efficient LIVE log-stream subscriber (createLogStream old:false live:true) ingests incoming relays and injects them into the local mirror room (dedup by mid, skips own → no loop). WebRTC SIGNAL frames are NOT relayed (too many/slow for the log). - Chosen over a muxrpc plugin because a classic pub only replicates the LOG (store-and-forward); live muxrpc wouldn't reach the other phone. No SSB-startup changes → no boot risk. Verified: boot OK with the live stream, invite/adopt register feeds, message posts + relay publishes, server stays up, 16/16 tests. Cross-device delivery needs the user's 2-phone+pub test. Note: text chat only — video still needs the wrapper camera permission (Fase 3).
This commit is contained in:
parent
2c2c8f241d
commit
6020c7f8df
3 changed files with 90 additions and 2 deletions
|
|
@ -40,6 +40,7 @@ module.exports = ({ idleTtlMs = DEFAULT_IDLE_TTL_MS, absTtlMs = DEFAULT_ABS_TTL_
|
|||
room.messages.length = 0;
|
||||
room.signals.length = 0;
|
||||
room.members.clear();
|
||||
room.remoteFeeds.clear();
|
||||
rooms.delete(id);
|
||||
};
|
||||
|
||||
|
|
@ -62,6 +63,7 @@ module.exports = ({ idleTtlMs = DEFAULT_IDLE_TTL_MS, absTtlMs = DEFAULT_ABS_TTL_
|
|||
messages: [],
|
||||
signals: [],
|
||||
members: new Set(),
|
||||
remoteFeeds: new Set(), // feeds SSB de otros nodos con esta sala (para relay cross-device por privados)
|
||||
seq: 0,
|
||||
sigSeq: 0,
|
||||
idleTimer: null,
|
||||
|
|
@ -74,6 +76,17 @@ module.exports = ({ idleTtlMs = DEFAULT_IDLE_TTL_MS, absTtlMs = DEFAULT_ABS_TTL_
|
|||
return publicRoom(room);
|
||||
};
|
||||
|
||||
// Fase 2 (cross-device): registra el feed SSB de otro participante (de una invitación) para relayarle.
|
||||
const addRemoteFeed = (id, feed) => {
|
||||
const room = rooms.get(id);
|
||||
if (!room || typeof feed !== "string" || !/^@[A-Za-z0-9+/=]{20,}\.ed25519$/.test(feed)) return false;
|
||||
if (room.remoteFeeds.has(feed) || room.remoteFeeds.size < MAX_MEMBERS) { room.remoteFeeds.add(feed); return true; }
|
||||
return false;
|
||||
};
|
||||
const getRemoteFeeds = (id) => { const r = rooms.get(id); return r ? [...r.remoteFeeds] : []; };
|
||||
// ¿hay ALGUNA sala con feeds remotos? (para no montar el relay si no hace falta)
|
||||
const anyRemoteRooms = () => { for (const r of rooms.values()) if (r.remoteFeeds.size) return true; return false; };
|
||||
|
||||
// Fase 2 (invitar): unirse a una sala por su id creando un ESPEJO local (desde un enlace/invitación).
|
||||
// El id es la "capacidad": quien lo tiene puede unirse. Aún NO conecta con la sala del otro nodo
|
||||
// (eso es la señalización cross-device, pendiente); crea la sala local para poder abrir el enlace.
|
||||
|
|
@ -91,7 +104,7 @@ module.exports = ({ idleTtlMs = DEFAULT_IDLE_TTL_MS, absTtlMs = DEFAULT_ABS_TTL_
|
|||
if (Number.isFinite(t) && t > 0) absMs = Math.min(t * 60000, MAX_ABS_TTL_MS);
|
||||
const room = {
|
||||
id, title: String(title || "").slice(0, 80), createdAt, expiresAt: createdAt + absMs,
|
||||
messages: [], signals: [], members: new Set(), seq: 0, sigSeq: 0, idleTimer: null, absTimer: null,
|
||||
messages: [], signals: [], members: new Set(), remoteFeeds: new Set(), seq: 0, sigSeq: 0, idleTimer: null, absTimer: null,
|
||||
};
|
||||
rooms.set(id, room);
|
||||
room.absTimer = setTimeout(() => destroy(id), absMs);
|
||||
|
|
@ -171,6 +184,9 @@ module.exports = ({ idleTtlMs = DEFAULT_IDLE_TTL_MS, absTtlMs = DEFAULT_ABS_TTL_
|
|||
return {
|
||||
createRoom,
|
||||
adoptRoom,
|
||||
addRemoteFeed,
|
||||
getRemoteFeeds,
|
||||
anyRemoteRooms,
|
||||
listRooms,
|
||||
getRoom,
|
||||
postMessage,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue