This commit is contained in:
legop3
2026-08-07 23:25:56 -04:00
parent 6c69c583c5
commit 6a6dec5540
8 changed files with 54 additions and 15 deletions
@@ -84,10 +84,29 @@ function listGrantedRoversForRequester(requesterKey) {
}
function applySocketGrantCache(socket) {
if (!socket) return;
if (!socket) return false;
socket.data = socket.data || {};
const requesterKey = buildRequesterKey(socket);
socket.data.privateClosedAccessRovers = listGrantedRoversForRequester(requesterKey);
const nextRoverIds = listGrantedRoversForRequester(requesterKey).sort();
const previousRoverIds = Array.isArray(socket.data.privateClosedAccessRovers)
? socket.data.privateClosedAccessRovers
: [];
const requesterChanged = socket.data.privateAccessRequesterKey !== requesterKey;
const grantsChanged = previousRoverIds.length !== nextRoverIds.length
|| previousRoverIds.some((roverId, index) => String(roverId) !== String(nextRoverIds[index]));
/*
Remember both inputs that determine the socket's private-access projection.
The requester key matters even when both identities currently have no grants,
because pending requests in the session payload are also keyed by requester.
Returning whether either input changed lets transport hooks avoid announcing
a false state change for ordinary live identity-setting updates.
*/
socket.data.privateAccessRequesterKey = requesterKey;
if (grantsChanged) {
socket.data.privateClosedAccessRovers = nextRoverIds;
}
return requesterChanged || grantsChanged;
}
function refreshAllSocketGrantCaches() {
@@ -71,8 +71,15 @@ function registerPrivateRoverAccessHooks(deps) {
socket.on('privateRover:requestAccess', handleRequest);
socket.on('session:privateRover:requestAccess', handleRequest);
socket.on('session:identify', () => {
applySocketGrantCache(socket);
requestEvents.emit('change', { reason: 'identify', socketId: socket.id });
/*
session:identify also carries unrelated live preferences such as audio
adjustments. Only publish a private-access change when identification
actually moved this socket to a different requester or grant set; a
no-op event must not fan out a full session sync to every connection.
*/
if (applySocketGrantCache(socket)) {
requestEvents.emit('change', { reason: 'identify', socketId: socket.id });
}
});
});
}