This commit is contained in:
Ylian Saint-Hilaire 2021-06-15 14:05:51 -07:00
parent db60c35a72
commit ce21e9a8cc
2 changed files with 21 additions and 4 deletions

View File

@ -1118,7 +1118,7 @@ function CreateMeshRelayEx2(parent, ws, req, domain, user, cookie) {
});
// If this session has a expire time, setup the expire timer now.
if (cookie && (typeof cookie.expire == 'number')) { obj.expireTimer = setTimeout(obj.close, cookie.expire - currentTime); }
setExpireTimer();
// Mark this relay session as authenticated if this is the user end.
obj.authenticated = (user != null);
@ -1205,6 +1205,21 @@ function CreateMeshRelayEx2(parent, ws, req, domain, user, cookie) {
}
}
// Set the session expire timer
function setExpireTimer() {
if (obj.expireTimer != null) { clearTimeout(obj.expireTimer); delete obj.expireTimer; }
if (cookie && (typeof cookie.expire == 'number')) {
const timeToExpire = (cookie.expire - Date.now());
if (timeToExpire < 1) {
obj.close();
} else if (timeToExpire >= 0x7FFFFFFF) {
obj.expireTimer = setTimeout(setExpireTimer, 0x7FFFFFFF); // Since expire timer can't be larger than 0x7FFFFFFF, reset timer after that time.
} else {
obj.expireTimer = setTimeout(obj.close, timeToExpire);
}
}
}
// If this is not an authenticated session, or the session does not have routing instructions, just go ahead an connect to existing session.
performRelay(0);
return obj;

View File

@ -619,9 +619,11 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
function setExpireTimer() {
if (obj.expireTimer != null) { clearTimeout(obj.expireTimer); delete obj.expireTimer; }
if (cookie && (typeof cookie.expire == 'number')) {
const timeToExpire = (cookie.expire - currentTime);
if (timeToExpire >= 0x7FFFFFFF) {
obj.expireTimer = setTimeout(setExpireTimer, 0x7FFFFFFF);
const timeToExpire = (cookie.expire - Date.now());
if (timeToExpire < 1) {
closeBothSides();
} else if (timeToExpire >= 0x7FFFFFFF) {
obj.expireTimer = setTimeout(setExpireTimer, 0x7FFFFFFF); // Since expire timer can't be larger than 0x7FFFFFFF, reset timer after that time.
} else {
obj.expireTimer = setTimeout(closeBothSides, timeToExpire);
}