TimeSynce.serverTime() behaving different in browsers

my Server side code
Meteor.methods({ 'doCount': function(){ var x = ProductList.find().count(); console.log(x); return x; } });

and client side code
Meteor.call('doCount', function(error, result) { console.log("lenght of counters variable is "+counters.length); var queryResult = ProductList.find().fetch(); for(i=0 ; i< result; i++){ console.log("current Time >>> "+ TimeSync.serverTime(); console.log("expire Time "+ queryResult[i].expire); } });
Two problems found,


  1. is thrown when user is logged-out
  2. is displaying only in Firefox console , Chrome is working fine

Try if (TimeSync.isSynced()) {console.log("current Time >>> "+ TimeSync.serverTime())}

Also, you have a missing closing paranthesis ) at the end of your first console.log() which may cause weird errors.

I don’t know what exactly is going on, I tried with TimeSync.resync(); and then pasted your code and it worked only once. I refreshed the browser and it’s gone.

What you could do is perhaps assign the server time to a session variable (since it possibly is global). That will make sure the sync takes place at its predefined interval and necessary reactive variables get updated.

You could then log the value of that session variable from within your client method.

I’m suggesting this because I believe you are having an issue with reactivity.

By the way , solved the problem by syncing the time in Meteor.startup

1 Like