meteor-user-status
meteor-user-status copied to clipboard
How do I start monitoring as soon as the client is synced?
In my application I want to start monitoring the user as he logs in. For that I looked at your demo app and wrote an analogous code:
Deps.autorun(function(c) {
UserStatus.startMonitor({
threshold: 1000,
interval: 1000,
idleOnBlur: false
}
But i'm always having the "Can't start idle monitor until synced to server" error. I suppose Deps.autorun isn't good sync identification. Don't really understand how it works in the demo actually, how the computation object marks that the server and client re in sync?
Possible solution may be to use timesync package, but I prefer to avoid from adding unnecessary packages .
Wrap in try block. startMonitor
reactively depends on sync status so it will re-run once synced.
See https://github.com/HarvardEconCS/turkserver-meteor/blob/master/client/ts_client.coffee#L41
safeStartMonitor = (threshold, idleOnBlur) ->
Deps.autorun (c) ->
try
settings = {threshold, idleOnBlur}
UserStatus.startMonitor(settings)
c.stop()
console.log "Idle monitor started with ", settings
I take no responsibility for low threshold and interval values which will result in an excessive traffic load on your server while providing little information of real value about whether clients are actually there.
Thanks, now it's working :+1:
The values are just for example, I understand they're impossibly low
I'm having a big issue maybe related to this. If I use the UserStatus.startMonitor my browser tab is frozen, all the app can't work because of just the line with startMonitor.
Here's my code:
Tracker.autorun(function () {
if(Meteor.userId() && !UserStatus.isMonitoring()){
try {
UserStatus.startMonitor({threshold:600000,interval:5000,idleOnBlur:false});
}
catch(err) {
console.log(err);
}
}else if(UserStatus.isMonitoring()){
UserStatus.stopMonitor();
}
});
@bitomule Looks like you're setting up an infinite loop there. UserStatus.isMonitoring()
is reactive.
@jonjamz So just remove the isMonitoring checks?
Tracker.autorun(function () { if(Meteor.userId()){ try { UserStatus.startMonitor({threshold:600000,interval:5000,idleOnBlur:false}); } catch(err) { console.log(err); } }else{ UserStatus.stopMonitor(); } });
This doesn't frozen the browser but I can't see the idle property on the user (it's published)
Fixed! thanks :)
Hi! I am having the same error. Here is my code: Meteor.startup(function() { try { Deps.autorun(function(c) { const monitoringOptions = { 'threshold' : 5000, 'interval' : 10000, 'idleOnBlur': true } UserStatus.startMonitor(monitoringOptions); c.stop(); }); } catch (e) { console.log(e); } });
http://stackoverflow.com/questions/29709568/meteorcant-start-idle-monitor-until-synced-to-server