Skip to content

Commit 0d970fd

Browse files
authored
[FIX] Refactor keep-alive to remove excessive calls to UserPresence (RocketChat#503)
* Refactoring keep alive so we dont call UserPresence excessively * Removes logic and Meteor call * remove away_time * Remove stoptimer and logs
1 parent 930e53f commit 0d970fd

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/public/preload.js

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals Meteor, Tracker, RocketChat */
1+
/* globals Meteor, Tracker, RocketChat, UserPresence*/
22
'use strict';
33

44
const { ipcRenderer, shell } = require('electron');
@@ -15,6 +15,20 @@ events.forEach(function (e) {
1515
});
1616
});
1717

18+
const userPresenceControl = () => {
19+
const INTERVAL = 10000; // 10s
20+
setInterval(() => {
21+
try {
22+
const idleTime = ipcRenderer.sendSync('getSystemIdleTime');
23+
if (idleTime < INTERVAL) {
24+
UserPresence.setOnline();
25+
}
26+
} catch (e) {
27+
console.error(`Error getting system idle time: ${e}`);
28+
}
29+
}, INTERVAL);
30+
};
31+
1832
window.addEventListener('load', function () {
1933
Meteor.startup(function () {
2034
Tracker.autorun(function () {
@@ -24,8 +38,8 @@ window.addEventListener('load', function () {
2438
}
2539
});
2640
});
41+
userPresenceControl();
2742
});
28-
2943
window.onload = function () {
3044
const $ = require('./vendor/jquery-3.1.1');
3145
function checkExternalUrl (e) {
@@ -34,7 +48,6 @@ window.onload = function () {
3448
if (RegExp(`^${location.protocol}\/\/${location.host}`).test(href)) {
3549
return;
3650
}
37-
3851
// Check href matching relative URL
3952
if (!/^([a-z]+:)?\/\//.test(href)) {
4053
return;
@@ -65,19 +78,3 @@ document.addEventListener('drop', e => e.preventDefault());
6578

6679
const spellChecker = new SpellCheck();
6780
spellChecker.enable();
68-
69-
/**
70-
* Keep user online if they are still using their computer
71-
*/
72-
const AWAY_TIME = 300000; // 5 mins
73-
const INTERVAL = 10000; // 10 seconds
74-
setInterval(function () {
75-
try {
76-
const idleTime = ipcRenderer.sendSync('getSystemIdleTime');
77-
if (idleTime < AWAY_TIME) {
78-
Meteor.call('UserPresence:online');
79-
}
80-
} catch (e) {
81-
console.error(`Error getting system idle time: ${e}`);
82-
}
83-
}, INTERVAL);

0 commit comments

Comments
 (0)