From be4da5fba4caf68fff93eefcb45cd349e39e374d Mon Sep 17 00:00:00 2001 From: David Glasser Date: Mon, 1 Oct 2012 13:45:54 -0700 Subject: [PATCH] Revert "Support unlimited tabs by working around browser per-hostname connection limits." This reverts commit 2495cb2f58c80f8517c4d9e76f47809a2f3942bc. This change made it easy to construct URLs with more than 63 characters in a label, which is not legal. We will redo this later with generating a smaller random token (and taking other precautions to limit the total size of the label). --- docs/client/api.js | 4 +-- packages/livedata/livedata_connection.js | 27 +++++++++++--------- packages/stream/stream_client.js | 32 +++++++----------------- 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/docs/client/api.js b/docs/client/api.js index a475ad5da9..44f167cf67 100644 --- a/docs/client/api.js +++ b/docs/client/api.js @@ -278,8 +278,8 @@ Template.api.connect = { descr: ["Connect to the server of a different Meteor application to subscribe to its document sets and invoke its remote methods."], args: [ {name: "url", - type: "String or function", - descr: "The URL of another Meteor application. May be a function returning an URL string, or an URL string. The function will be called each time an URL is needed (immediately and on reconnects); it is expected to always return URLs pointing to the same server, but may add randomness to the hostname in order to get around browser per-hostname connection limitations. If a string is provided and it contains the string `MeteorWildcard`, that substring will be replaced by a random string of alphanumerics and hyphens."} + type: "String", + descr: "The URL of another Meteor application."} ] }; diff --git a/packages/livedata/livedata_connection.js b/packages/livedata/livedata_connection.js index 2da2c38355..27350ab93c 100644 --- a/packages/livedata/livedata_connection.js +++ b/packages/livedata/livedata_connection.js @@ -10,12 +10,21 @@ if (Meteor.isServer) { // XXX namespacing Meteor._capture_subs = null; -// @param url {Function|String|Object} URL or URL-producing function to Meteor -// app or sockjs endpoint (deprecated), or an object as a test hook (see -// code) +// @param url {String|Object} URL to Meteor app or sockjs endpoint (deprecated), +// or an object as a test hook (see code) Meteor._LivedataConnection = function (url, restart_on_update) { var self = this; + // as a test hook, allow passing a stream instead of a url. + if (typeof url === "object") { + self.stream = url; + // if we have two test streams, auto reload stuff will break because + // the url is used as a key for the migration data. + self.url = "/debug"; + } else { + self.url = url; + } + self.last_session_id = null; self.stores = {}; // name -> object with methods self.method_handlers = {}; // name -> func @@ -55,13 +64,8 @@ Meteor._LivedataConnection = function (url, restart_on_update) { return [true]; }); - // Set up stream. As a test hook, allow passing a stream instead of an url or - // url-producing function. - if (typeof url === "object") { - self.stream = url; - } else { - self.stream = new Meteor._Stream(url); - } + // Setup stream (if not overriden above) + self.stream = self.stream || new Meteor._Stream(self.url); self.stream.on('message', function (raw_msg) { try { @@ -557,8 +561,7 @@ _.extend(Meteor._LivedataConnection.prototype, { }); _.extend(Meteor, { - // @param url {String|Function} URL or URL-producing function to Meteor app, - // or to sockjs endpoint (deprecated), + // @param url {String} URL to Meteor app, or to sockjs endpoint (deprecated), // e.g.: // "subdomain.meteor.com", // "http://subdomain.meteor.com", diff --git a/packages/stream/stream_client.js b/packages/stream/stream_client.js index a25f5e7853..0f70866b75 100644 --- a/packages/stream/stream_client.js +++ b/packages/stream/stream_client.js @@ -1,19 +1,9 @@ -// @param url {Function|String} URL or URL-producing function to Meteor app or -// sockjs endpoint (deprecated) "http://subdomain.meteor.com/sockjs" or -// "/sockjs" +// @param url {String} URL to Meteor app or sockjs endpoint (deprecated) +// "http://subdomain.meteor.com/sockjs" or "/sockjs" Meteor._Stream = function (url) { var self = this; - if (typeof(url) === 'string') { - self.url = function () { - return url.replace(/MeteorWildcard/g, Meteor.uuid); - }; - } else if (typeof(url) === 'function') { - self.url = url; - } else { - throw new Error("Stream url must be string or function: " + url); - } - + self.url = Meteor._Stream._toSockjsUrl(url); self.socket = null; self.event_callbacks = {}; // name -> [callback] self.server_id = null; @@ -323,16 +313,12 @@ _.extend(Meteor._Stream.prototype, { var self = this; self._cleanup_socket(); // cleanup the old socket, if there was one. - // Generate a new URL each time we open a connection, so that we can connect - // to random hostnames and get around browser per-host connection limits. - self.socket = new SockJS( - Meteor._Stream._toSockjsUrl(self.url()), - undefined, - { debug: false, protocols_whitelist: [ - // only allow polling protocols. no websockets or streaming. - // streaming makes safari spin, and websockets hurt chrome. - 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling' - ]}); + self.socket = new SockJS(self.url, undefined, { + debug: false, protocols_whitelist: [ + // only allow polling protocols. no websockets or streaming. + // streaming makes safari spin, and websockets hurt chrome. + 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling' + ]}); self.socket.onmessage = function (data) { // first message we get when we're connecting goes to _connected, // which connects us. All subsequent messages (while connected) go to