Home

Awesome

meteor-timesync Build Status

NTP-style time synchronization between server and client, and facilities to use server time reactively in Meteor applications.

What's this do?

Meteor clients don't necessarily have accurate timestamps relative to your server. This package computes and maintains an offset between server and client, allowing server timestamps to be used on the client (especially for displaying time differences). It also provides facilities to use time reactively in your application.

There is a demo as part of the user-status app at http://user-status.meteor.com.

Installation

meteor add mizzao:timesync

Usage

To use the above functions in a non-reactive context, use Deps.nonreactive. This is useful if you are displaying a lot of timestamps or differences on a page and you don't want them to be constantly recomputed on the client. However, displaying time reactively should be pretty efficient with Meteor 0.8.0+ (Blaze).

Note that TimeSync.serverTime returns a timestamp, not a Date, but you can easily construct a date with new Date(TimeSync.serverTime(...)).

You can also use something like TimeSync.serverTime(null, 5000) to get a reactive time value that only updates at 5 second intervals. All reactive time variables with the same value of updateInterval are guaranteed to be invalidated at the same time.

Notes