-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW] Disconnect users from websocket when away from the login screen…
… for 10min (#11086)
- Loading branch information
1 parent
401e2e2
commit e2d8494
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export const LoginPresence = { | ||
awayTime: 600000, //10 minutes | ||
started: false, | ||
|
||
startTimer() { | ||
LoginPresence.stopTimer(); | ||
if (!LoginPresence.awayTime) { | ||
return; | ||
} | ||
this.timer = setTimeout(LoginPresence.disconnect, LoginPresence.awayTime); | ||
}, | ||
stopTimer() { | ||
clearTimeout(this.timer); | ||
}, | ||
disconnect() { | ||
const status = Meteor.status(); | ||
if (status && status.status !== 'offline') { | ||
if (!Meteor.userId() && RocketChat.settings.get('Accounts_AllowAnonymousRead') !== true) { | ||
Meteor.disconnect(); | ||
} | ||
} | ||
LoginPresence.stopTimer(); | ||
}, | ||
connect() { | ||
const status = Meteor.status(); | ||
if (status && status.status === 'offline') { | ||
Meteor.reconnect(); | ||
} | ||
}, | ||
start() { | ||
if (LoginPresence.started) { | ||
return; | ||
} | ||
|
||
window.addEventListener('focus', () => { | ||
LoginPresence.stopTimer(); | ||
LoginPresence.connect(); | ||
}); | ||
|
||
window.addEventListener('blur', () => { | ||
LoginPresence.startTimer(); | ||
}); | ||
|
||
if (!window.document.hasFocus()) { | ||
LoginPresence.startTimer(); | ||
} | ||
|
||
LoginPresence.started = true; | ||
} | ||
}; | ||
|
||
LoginPresence.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters