meteor-user-status icon indicating copy to clipboard operation
meteor-user-status copied to clipboard

How do I start monitoring as soon as the client is synced?

Open leonprou opened this issue 10 years ago • 8 comments

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 .

leonprou avatar Aug 11 '14 20:08 leonprou

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.

mizzao avatar Aug 11 '14 20:08 mizzao

Thanks, now it's working :+1:
The values are just for example, I understand they're impossibly low

leonprou avatar Aug 12 '14 17:08 leonprou

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 avatar Oct 16 '14 11:10 bitomule

@bitomule Looks like you're setting up an infinite loop there. UserStatus.isMonitoring() is reactive.

jonjamz avatar Oct 16 '14 11:10 jonjamz

@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)

bitomule avatar Oct 16 '14 11:10 bitomule

Fixed! thanks :)

bitomule avatar Oct 16 '14 12:10 bitomule

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); } });

NaviivaN21 avatar Sep 23 '16 08:09 NaviivaN21

http://stackoverflow.com/questions/29709568/meteorcant-start-idle-monitor-until-synced-to-server

advancedsoftwarecanada avatar May 19 '17 12:05 advancedsoftwarecanada