mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 09:31:20 -04:00
crocs
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user