diff --git a/lib/www/server/ws/index.js b/lib/www/server/ws/index.js index 53763d4..6d0e6ff 100644 --- a/lib/www/server/ws/index.js +++ b/lib/www/server/ws/index.js @@ -20,8 +20,10 @@ function start (server, pingInterval=30000) { const exp = decoded?.exp; if (exp) { const timeout = (exp*1000 - Date.now()) / 2; - socket._jwtRefresh = setTimeout(() => refreshJwt(token), timeout); - console.log(`Scheduled JWT refresh in ${timeout/1000} seconds at time ${(new Date(Date.now() + timeout)).toISOString()}`); + if (!socket._jwtRefresh) { + socket._jwtRefresh = setTimeout(() => refreshJwt(token), timeout); + console.log(`Scheduled JWT refresh in ${timeout/1000} seconds at time ${(new Date(Date.now() + timeout)).toISOString()}`); + } } else { console.log("Token has no exp claim. Refresh not scheduled"); } @@ -76,8 +78,8 @@ function start (server, pingInterval=30000) { }); socket.on('close', () => { - if (socket._jwtTimeout) { - clearTimeout(socket._jwtTimeout); + if (socket._jwtRefresh) { + clearTimeout(socket._jwtRefresh); } }); });