Merge branch 'autoupdate-review-from-glasser' into devel

This commit is contained in:
Nick Martin
2013-11-21 16:42:47 -08:00
8 changed files with 43 additions and 36 deletions

View File

@@ -103,7 +103,7 @@ WebApp.connectHandlers.use(function(req, res, next) {
// reload again trying to get the new code.
if (Package.autoupdate) {
var version = Package.autoupdate.AutoUpdate.autoUpdateVersion;
var version = Package.autoupdate.Autoupdate.autoupdateVersion;
if (version !== WebApp.clientHash)
manifest += "# " + version + "\n";
}

View File

@@ -59,7 +59,7 @@ so it doesn't wait for new files to download before displaying the web
page.
## AutoUpdate.newClientAvailable
## Autoupdate.newClientAvailable
Undo previous changes made, such as by using `git checkout .` Reload
the client, which will cause the browser to stop using the app cache.
@@ -75,7 +75,7 @@ see the variable without having the client also reload.
Add to leaderboard.js:
Template.leaderboard.available = AutoUpdate.newClientAvailable;
Template.leaderboard.available = Autoupdate.newClientAvailable;
And add `{{available}}` to the leaderboard template in
leaderboard.html.

View File

@@ -1,20 +1,20 @@
// Subscribe to the `meteor_autoupdate_clientVersions` collection,
// which contains the set of acceptable client versions.
//
// A "hard code push" occurs when the current client version is not in
// A "hard code push" occurs when the running client version is not in
// the set of acceptable client versions (or the server updates the
// collection, and the current client version is no longer in the
// set).
// collection, there is a published client version marked `current` and
// the running client version is no longer in the set).
//
// When the `reload` package is loaded, a hard code push causes
// the browser to reload, so that it will load the latest client
// version from the server.
//
// A "soft code push" represents the situation when the current client
// A "soft code push" represents the situation when the running client
// version is in the set of acceptable versions, but there is a newer
// version available on the server.
//
// `AutoUpdate.newClientAvailable` is a reactive data source which
// `Autoupdate.newClientAvailable` is a reactive data source which
// becomes `true` if there is a new version of the client is available on
// the server.
//
@@ -24,20 +24,20 @@
// The client version of the client code currently running in the
// browser.
var autoUpdateVersion = __meteor_runtime_config__.autoUpdateVersion;
var autoupdateVersion = __meteor_runtime_config__.autoupdateVersion || "unknown";
// The collection of acceptable client versions.
var ClientVersions = new Meteor.Collection("meteor_autoupdate_clientVersions");
AutoUpdate = {};
Autoupdate = {};
AutoUpdate.newClientAvailable = function () {
Autoupdate.newClientAvailable = function () {
return !! ClientVersions.findOne(
{$and: [
{current: true},
{_id: {$ne: autoUpdateVersion}}
{_id: {$ne: autoupdateVersion}}
]}
);
};
@@ -51,7 +51,7 @@ Meteor.subscribe("meteor_autoupdate_clientVersions", {
if (Package.reload) {
Deps.autorun(function (computation) {
if (ClientVersions.findOne({current: true}) &&
(! ClientVersions.findOne({_id: autoUpdateVersion}))) {
(! ClientVersions.findOne({_id: autoupdateVersion}))) {
computation.stop();
Package.reload.Reload._reload();
}

View File

@@ -35,24 +35,26 @@
// client version. Developers can easily experiment with different
// versioning and updating models by forking this package.
AutoUpdate = {};
Autoupdate = {};
// The client hash includes __meteor_runtime_config__, so wait until
// all packages have loaded and have had a chance to populate the
// runtime config before using the client hash as our default auto
// update version id.
AutoUpdate.autoUpdateVersion = null;
Autoupdate.autoupdateVersion = null;
Meteor.startup(function () {
if (AutoUpdate.autoUpdateVersion === null)
AutoUpdate.autoUpdateVersion =
// Allow people to override Autoupdate.autoupdateVersion before
// startup. Tests do this.
if (Autoupdate.autoupdateVersion === null)
Autoupdate.autoupdateVersion =
process.env.AUTOUPDATE_VERSION ||
process.env.SERVER_ID ||
process.env.SERVER_ID || // XXX COMPAT 0.6.6
WebApp.clientHash;
// Make autoUpdateVersion available on the client.
__meteor_runtime_config__.autoUpdateVersion = AutoUpdate.autoUpdateVersion;
// Make autoupdateVersion available on the client.
__meteor_runtime_config__.autoupdateVersion = Autoupdate.autoupdateVersion;
});
@@ -60,15 +62,20 @@ Meteor.publish(
"meteor_autoupdate_clientVersions",
function () {
var self = this;
// Using `autoUpdateVersion` here is safe because we can't get a
// Using `autoupdateVersion` here is safe because we can't get a
// subscription before webapp starts listening, and it doesn't do
// that until the startup hooks have run.
self.added(
"meteor_autoupdate_clientVersions",
AutoUpdate.autoUpdateVersion,
{current: true}
);
self.ready();
if (Autoupdate.autoupdateVersion) {
self.added(
"meteor_autoupdate_clientVersions",
Autoupdate.autoupdateVersion,
{current: true}
);
self.ready();
} else {
// huh? shouldn't happen. Just error the sub.
self.error(new Meteor.Error(500, "Autoupdate.autoupdateVersion not set"));
}
},
{is_auto: true}
);

View File

@@ -7,7 +7,7 @@ Package.on_use(function (api) {
api.use(['livedata', 'mongo-livedata'], ['client', 'server']);
api.use('reload', 'client', {weak: true});
api.export('AutoUpdate');
api.export('Autoupdate');
api.add_files('autoupdate_server.js', 'server');
api.add_files('autoupdate_client.js', 'client');
});

View File

@@ -181,9 +181,9 @@ var Connection = function (url, options) {
}
if (msg === null || !msg.msg) {
// DEPRECATED. ignore the old welcome message for back compat.
// Remove this 'if' once the server stops sending welcome messages
// (stream_server.js).
// XXX COMPAT WITH 0.6.6. ignore the old welcome message for back
// compat. Remove this 'if' once the server stops sending welcome
// messages (stream_server.js).
if (! (msg && msg.server_id))
Meteor._debug("discarding invalid livedata message", msg);
return;

View File

@@ -65,10 +65,10 @@ StreamServer = function () {
});
self.open_sockets.push(socket);
// DEPRECATED. Send the old style welcome message, which will force
// old clients to reload. Remove this once we're not concerned about
// people upgrading from a pre-0.6.7 release. Also, remove the
// clause in the client that ignores the welcome message
// XXX COMPAT WITH 0.6.6. Send the old style welcome message, which
// will force old clients to reload. Remove this once we're not
// concerned about people upgrading from a pre-0.6.7 release. Also,
// remove the clause in the client that ignores the welcome message
// (livedata_connection.js)
socket.send(JSON.stringify({server_id: "0"}));

View File

@@ -4,4 +4,4 @@
// different value when the server restarts accomplishes this.
if (Package.autoupdate)
Package.autoupdate.AutoUpdate.autoUpdateVersion = Random.id();
Package.autoupdate.Autoupdate.autoupdateVersion = Random.id();