mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Convert ddp-client to use only api.mainModule for client and server
This commit is contained in:
14
packages/ddp-client/client.js
Normal file
14
packages/ddp-client/client.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { DDP, LivedataTest } from './namespace';
|
||||
|
||||
import './livedata_common';
|
||||
|
||||
import './sockjs-0.3.4';
|
||||
import './stream_client_sockjs';
|
||||
import './stream_client_common';
|
||||
|
||||
import './random_stream';
|
||||
import './livedata_connection';
|
||||
|
||||
import './client_convenience';
|
||||
|
||||
export { DDP, LivedataTest };
|
||||
@@ -1,4 +1,6 @@
|
||||
import { DDP, LivedataTest } from "./namespace.js";
|
||||
import { DDPCommon } from 'meteor/ddp-common';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
LivedataTest.SUPPORTED_DDP_VERSIONS = DDPCommon.SUPPORTED_DDP_VERSIONS;
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { DDP, LivedataTest } from "./namespace.js";
|
||||
import { MongoIDMap } from "./id_map.js";
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { DDPCommon } from 'meteor/ddp-common';
|
||||
import { Tracker } from 'meteor/tracker';
|
||||
import { EJSON } from 'meteor/ejson';
|
||||
import { Random } from 'meteor/random';
|
||||
|
||||
if (Meteor.isServer) {
|
||||
var Fiber = Npm.require('fibers');
|
||||
|
||||
@@ -27,19 +27,10 @@ Package.onUse(function (api) {
|
||||
// _idParse, _idStringify.
|
||||
api.use('mongo-id', ['client', 'server']);
|
||||
|
||||
api.addFiles(['sockjs-0.3.4.js', 'stream_client_sockjs.js'], 'client');
|
||||
api.addFiles('stream_client_nodejs.js', 'server');
|
||||
api.addFiles('stream_client_common.js', ['client', 'server']);
|
||||
|
||||
api.addFiles('livedata_common.js', ['client', 'server']);
|
||||
api.addFiles('random_stream.js', ['client', 'server']);
|
||||
|
||||
api.addFiles('livedata_connection.js', ['client', 'server']);
|
||||
|
||||
api.addFiles('client_convenience.js', 'client');
|
||||
|
||||
api.mainModule("namespace.js");
|
||||
// For backcompat where things use Package.ddp.DDP, etc
|
||||
api.export('DDP');
|
||||
api.mainModule("client.js", "client");
|
||||
api.mainModule("server.js", "server");
|
||||
});
|
||||
|
||||
Package.onTest(function (api) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DDP } from "./namespace.js";
|
||||
import { DDPCommon } from 'meteor/ddp-common';
|
||||
|
||||
// Returns the named sequence of pseudo-random values.
|
||||
// The scope will be DDP._CurrentMethodInvocation.get(), so the stream will produce
|
||||
|
||||
11
packages/ddp-client/server.js
Normal file
11
packages/ddp-client/server.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { DDP, LivedataTest } from './namespace';
|
||||
|
||||
import './livedata_common';
|
||||
|
||||
import './stream_client_nodejs';
|
||||
import './stream_client_common';
|
||||
|
||||
import './random_stream';
|
||||
import './livedata_connection';
|
||||
|
||||
export { DDP, LivedataTest };
|
||||
@@ -1,90 +1,11 @@
|
||||
import { DDP, LivedataTest } from "./namespace.js";
|
||||
import { Random } from 'meteor/random';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { Tracker } from 'meteor/tracker';
|
||||
import { Retry } from 'meteor/retry';
|
||||
|
||||
// XXX from Underscore.String (http://epeli.github.com/underscore.string/)
|
||||
var startsWith = function(str, starts) {
|
||||
return str.length >= starts.length &&
|
||||
str.substring(0, starts.length) === starts;
|
||||
};
|
||||
var endsWith = function(str, ends) {
|
||||
return str.length >= ends.length &&
|
||||
str.substring(str.length - ends.length) === ends;
|
||||
};
|
||||
|
||||
// @param url {String} URL to Meteor app, eg:
|
||||
// "/" or "madewith.meteor.com" or "https://foo.meteor.com"
|
||||
// or "ddp+sockjs://ddp--****-foo.meteor.com/sockjs"
|
||||
// @returns {String} URL to the endpoint with the specific scheme and subPath, e.g.
|
||||
// for scheme "http" and subPath "sockjs"
|
||||
// "http://subdomain.meteor.com/sockjs" or "/sockjs"
|
||||
// or "https://ddp--1234-foo.meteor.com/sockjs"
|
||||
var translateUrl = function(url, newSchemeBase, subPath) {
|
||||
if (! newSchemeBase) {
|
||||
newSchemeBase = "http";
|
||||
}
|
||||
|
||||
var ddpUrlMatch = url.match(/^ddp(i?)\+sockjs:\/\//);
|
||||
var httpUrlMatch = url.match(/^http(s?):\/\//);
|
||||
var newScheme;
|
||||
if (ddpUrlMatch) {
|
||||
// Remove scheme and split off the host.
|
||||
var urlAfterDDP = url.substr(ddpUrlMatch[0].length);
|
||||
newScheme = ddpUrlMatch[1] === "i" ? newSchemeBase : newSchemeBase + "s";
|
||||
var slashPos = urlAfterDDP.indexOf('/');
|
||||
var host =
|
||||
slashPos === -1 ? urlAfterDDP : urlAfterDDP.substr(0, slashPos);
|
||||
var rest = slashPos === -1 ? '' : urlAfterDDP.substr(slashPos);
|
||||
|
||||
// In the host (ONLY!), change '*' characters into random digits. This
|
||||
// allows different stream connections to connect to different hostnames
|
||||
// and avoid browser per-hostname connection limits.
|
||||
host = host.replace(/\*/g, function () {
|
||||
return Math.floor(Random.fraction()*10);
|
||||
});
|
||||
|
||||
return newScheme + '://' + host + rest;
|
||||
} else if (httpUrlMatch) {
|
||||
newScheme = !httpUrlMatch[1] ? newSchemeBase : newSchemeBase + "s";
|
||||
var urlAfterHttp = url.substr(httpUrlMatch[0].length);
|
||||
url = newScheme + "://" + urlAfterHttp;
|
||||
}
|
||||
|
||||
// Prefix FQDNs but not relative URLs
|
||||
if (url.indexOf("://") === -1 && !startsWith(url, "/")) {
|
||||
url = newSchemeBase + "://" + url;
|
||||
}
|
||||
|
||||
// XXX This is not what we should be doing: if I have a site
|
||||
// deployed at "/foo", then DDP.connect("/") should actually connect
|
||||
// to "/", not to "/foo". "/" is an absolute path. (Contrast: if
|
||||
// deployed at "/foo", it would be reasonable for DDP.connect("bar")
|
||||
// to connect to "/foo/bar").
|
||||
//
|
||||
// We should make this properly honor absolute paths rather than
|
||||
// forcing the path to be relative to the site root. Simultaneously,
|
||||
// we should set DDP_DEFAULT_CONNECTION_URL to include the site
|
||||
// root. See also client_convenience.js #RationalizingRelativeDDPURLs
|
||||
url = Meteor._relativeToSiteRootUrl(url);
|
||||
|
||||
if (endsWith(url, "/"))
|
||||
return url + subPath;
|
||||
else
|
||||
return url + "/" + subPath;
|
||||
};
|
||||
|
||||
toSockjsUrl = function (url) {
|
||||
return translateUrl(url, "http", "sockjs");
|
||||
};
|
||||
|
||||
toWebsocketUrl = function (url) {
|
||||
var ret = translateUrl(url, "ws", "websocket");
|
||||
return ret;
|
||||
};
|
||||
|
||||
LivedataTest.toSockjsUrl = toSockjsUrl;
|
||||
|
||||
|
||||
_.extend(LivedataTest.ClientStream.prototype, {
|
||||
|
||||
// Register for callbacks.
|
||||
on: function (name, callback) {
|
||||
var self = this;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { DDP, LivedataTest } from "./namespace.js";
|
||||
import { DDP, LivedataTest } from "./namespace";
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { toWebsocketUrl } from './urlHelpers';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
// @param endpoint {String} URL to Meteor app
|
||||
// "http://subdomain.meteor.com/" or "/" or
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { DDP, LivedataTest } from "./namespace.js";
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { toSockjsUrl } from './urlHelpers';
|
||||
|
||||
// @param url {String} URL to Meteor app
|
||||
// "http://subdomain.meteor.com/" or "/" or
|
||||
|
||||
84
packages/ddp-client/urlHelpers.js
Normal file
84
packages/ddp-client/urlHelpers.js
Normal file
@@ -0,0 +1,84 @@
|
||||
import { LivedataTest } from './namespace';
|
||||
import { Random } from 'meteor/random';
|
||||
|
||||
// XXX from Underscore.String (http://epeli.github.com/underscore.string/)
|
||||
var startsWith = function(str, starts) {
|
||||
return str.length >= starts.length &&
|
||||
str.substring(0, starts.length) === starts;
|
||||
};
|
||||
var endsWith = function(str, ends) {
|
||||
return str.length >= ends.length &&
|
||||
str.substring(str.length - ends.length) === ends;
|
||||
};
|
||||
|
||||
// @param url {String} URL to Meteor app, eg:
|
||||
// "/" or "madewith.meteor.com" or "https://foo.meteor.com"
|
||||
// or "ddp+sockjs://ddp--****-foo.meteor.com/sockjs"
|
||||
// @returns {String} URL to the endpoint with the specific scheme and subPath, e.g.
|
||||
// for scheme "http" and subPath "sockjs"
|
||||
// "http://subdomain.meteor.com/sockjs" or "/sockjs"
|
||||
// or "https://ddp--1234-foo.meteor.com/sockjs"
|
||||
var translateUrl = function(url, newSchemeBase, subPath) {
|
||||
if (! newSchemeBase) {
|
||||
newSchemeBase = "http";
|
||||
}
|
||||
|
||||
var ddpUrlMatch = url.match(/^ddp(i?)\+sockjs:\/\//);
|
||||
var httpUrlMatch = url.match(/^http(s?):\/\//);
|
||||
var newScheme;
|
||||
if (ddpUrlMatch) {
|
||||
// Remove scheme and split off the host.
|
||||
var urlAfterDDP = url.substr(ddpUrlMatch[0].length);
|
||||
newScheme = ddpUrlMatch[1] === "i" ? newSchemeBase : newSchemeBase + "s";
|
||||
var slashPos = urlAfterDDP.indexOf('/');
|
||||
var host =
|
||||
slashPos === -1 ? urlAfterDDP : urlAfterDDP.substr(0, slashPos);
|
||||
var rest = slashPos === -1 ? '' : urlAfterDDP.substr(slashPos);
|
||||
|
||||
// In the host (ONLY!), change '*' characters into random digits. This
|
||||
// allows different stream connections to connect to different hostnames
|
||||
// and avoid browser per-hostname connection limits.
|
||||
host = host.replace(/\*/g, function () {
|
||||
return Math.floor(Random.fraction()*10);
|
||||
});
|
||||
|
||||
return newScheme + '://' + host + rest;
|
||||
} else if (httpUrlMatch) {
|
||||
newScheme = !httpUrlMatch[1] ? newSchemeBase : newSchemeBase + "s";
|
||||
var urlAfterHttp = url.substr(httpUrlMatch[0].length);
|
||||
url = newScheme + "://" + urlAfterHttp;
|
||||
}
|
||||
|
||||
// Prefix FQDNs but not relative URLs
|
||||
if (url.indexOf("://") === -1 && !startsWith(url, "/")) {
|
||||
url = newSchemeBase + "://" + url;
|
||||
}
|
||||
|
||||
// XXX This is not what we should be doing: if I have a site
|
||||
// deployed at "/foo", then DDP.connect("/") should actually connect
|
||||
// to "/", not to "/foo". "/" is an absolute path. (Contrast: if
|
||||
// deployed at "/foo", it would be reasonable for DDP.connect("bar")
|
||||
// to connect to "/foo/bar").
|
||||
//
|
||||
// We should make this properly honor absolute paths rather than
|
||||
// forcing the path to be relative to the site root. Simultaneously,
|
||||
// we should set DDP_DEFAULT_CONNECTION_URL to include the site
|
||||
// root. See also client_convenience.js #RationalizingRelativeDDPURLs
|
||||
url = Meteor._relativeToSiteRootUrl(url);
|
||||
|
||||
if (endsWith(url, "/"))
|
||||
return url + subPath;
|
||||
else
|
||||
return url + "/" + subPath;
|
||||
};
|
||||
|
||||
export function toSockjsUrl(url) {
|
||||
return translateUrl(url, "http", "sockjs");
|
||||
};
|
||||
|
||||
export function toWebsocketUrl(url) {
|
||||
var ret = translateUrl(url, "ws", "websocket");
|
||||
return ret;
|
||||
};
|
||||
|
||||
LivedataTest.toSockjsUrl = toSockjsUrl;
|
||||
Reference in New Issue
Block a user