mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
dead socket kicking and connection info pill
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -11,8 +11,8 @@
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<meta name="apple-mobile-web-app-title" content="Roomba Rover" />
|
||||
<title>Roomba Rover</title>
|
||||
<script type="module" crossorigin src="/assets/index-IYeJHM9w.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-BsongPZ9.css">
|
||||
<script type="module" crossorigin src="/assets/index-4wUtzGNB.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-BpQe7PYg.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -14,11 +14,14 @@ function registerVerificationHooks(deps) {
|
||||
} = deps;
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
socket.data = socket.data || {};
|
||||
socket.data.connectedAt = Date.now();
|
||||
identifySocket(socket, {});
|
||||
|
||||
socket.on('session:identify', (payload = {}, cb = () => {}) => {
|
||||
try {
|
||||
const result = identifySocket(socket, payload || {});
|
||||
socket.data.lastClientIdentifyAt = Date.now();
|
||||
cb({ success: true, ...result });
|
||||
} catch (err) {
|
||||
cb({ error: err.message });
|
||||
|
||||
@@ -28,6 +28,8 @@ const { createRequestFlow } = require('./requestFlow');
|
||||
const { registerVerificationHooks } = require('./hooks');
|
||||
|
||||
const verificationEvents = new EventEmitter();
|
||||
const IDENTITY_TIMEOUT_MS = 2 * 60 * 1000;
|
||||
const IDENTITY_SWEEP_INTERVAL_MS = 15 * 1000;
|
||||
|
||||
function emitChange(reason, payload = {}) {
|
||||
verificationEvents.emit('change', { reason, ...payload });
|
||||
@@ -145,6 +147,27 @@ registerVerificationHooks({
|
||||
emitChange,
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
const now = Date.now();
|
||||
io.sockets.sockets.forEach((socket) => {
|
||||
if (!socket?.id) return;
|
||||
const role = getRole(socket);
|
||||
if (role === 'admin' || role === 'lockdown') return;
|
||||
const connectedAt = Number(socket?.data?.connectedAt || 0);
|
||||
const lastClientIdentifyAt = Number(socket?.data?.lastClientIdentifyAt || 0);
|
||||
const referenceTs = lastClientIdentifyAt || connectedAt;
|
||||
if (!referenceTs) return;
|
||||
if (now - referenceTs < IDENTITY_TIMEOUT_MS) return;
|
||||
logger.info('Disconnecting socket due to stale identity heartbeat', {
|
||||
socketId: socket.id,
|
||||
role,
|
||||
ageMs: now - referenceTs,
|
||||
hadClientIdentify: Boolean(lastClientIdentifyAt),
|
||||
});
|
||||
socket.disconnect(true);
|
||||
});
|
||||
}, IDENTITY_SWEEP_INTERVAL_MS);
|
||||
|
||||
module.exports = {
|
||||
identifySocket,
|
||||
getVerificationStatus: verificationFlow.getVerificationStatus,
|
||||
|
||||
Reference in New Issue
Block a user