From 2bcd692b54075be7eaf55d804c5f018c5b15f3f5 Mon Sep 17 00:00:00 2001 From: Geoff Schmidt Date: Thu, 28 Mar 2013 06:26:36 -0700 Subject: [PATCH] livedata: if client_convenience.js is loaded "on the server" (not normally possible in the usual build scenario, but would be the case of a nodejs-based client, eg, a command-line tool), don't try to open a default DDP connection --- packages/livedata/client_convenience.js | 40 ++++++++++++++----------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/packages/livedata/client_convenience.js b/packages/livedata/client_convenience.js index 3eb4ef8ddc..b049d630c4 100644 --- a/packages/livedata/client_convenience.js +++ b/packages/livedata/client_convenience.js @@ -1,22 +1,28 @@ -// By default, try to connect back to the same endpoint as the page -// was served from. -var ddpUrl = '/'; -if (typeof __meteor_runtime_config__ !== "undefined") { - if (__meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL) - ddpUrl = __meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL; -} - _.extend(Meteor, { - default_connection: Meteor.connect(ddpUrl, true /* restart_on_update */), - + default_connection: null, refresh: function (notification) { } }); -// Proxy the public methods of Meteor.default_connection so they can -// be called directly on Meteor. -_.each(['subscribe', 'methods', 'call', 'apply', 'status', 'reconnect'], - function (name) { - Meteor[name] = _.bind(Meteor.default_connection[name], - Meteor.default_connection); - }); +if (Meteor.isClient) { + // By default, try to connect back to the same endpoint as the page + // was served from. + var ddpUrl = '/'; + if (typeof __meteor_runtime_config__ !== "undefined") { + if (__meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL) + ddpUrl = __meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL; + } + Meteor.default_connection = + Meteor.connect(ddpUrl, true /* restart_on_update */); + + // Proxy the public methods of Meteor.default_connection so they can + // be called directly on Meteor. + _.each(['subscribe', 'methods', 'call', 'apply', 'status', 'reconnect'], + function (name) { + Meteor[name] = _.bind(Meteor.default_connection[name], + Meteor.default_connection); + }); +} else { + /* Never set up a default connection on the server. Don't even map + subscribe/call/etc onto Meteor. */ +}