mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Meteor.connect to ourself as a server now works. Code still needs some cleaning up
This commit is contained in:
2
packages/livedata/.npm/npm-shrinkwrap.json
generated
2
packages/livedata/.npm/npm-shrinkwrap.json
generated
@@ -16,7 +16,7 @@
|
||||
},
|
||||
"websocket": {
|
||||
"version": "1.0.7",
|
||||
"from": "websocket@1.0.7",
|
||||
"from": "https://registry.npmjs.org/websocket/-/websocket-1.0.7.tgz",
|
||||
"resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.7.tgz"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
if (Meteor.isServer) {
|
||||
// XXX namespacing
|
||||
var path = Npm.require('path');
|
||||
var Future = Npm.require(path.join('fibers', 'future'));
|
||||
}
|
||||
|
||||
|
||||
@@ -597,6 +597,27 @@ if (Meteor.isClient) {
|
||||
]);
|
||||
}
|
||||
|
||||
(function () {
|
||||
if (Meteor.isServer) {
|
||||
Meteor.methods({
|
||||
"s2s": function (arg) {
|
||||
return "s2s " + arg;
|
||||
}
|
||||
});
|
||||
}
|
||||
var conn;
|
||||
testAsyncMulti("livedata - connect works from both client and server", [
|
||||
function (test, expect) {
|
||||
conn = Meteor.connect(Meteor.absoluteUrl());
|
||||
conn.call('s2s', 'foo', expect(function (err, res) {
|
||||
if (err)
|
||||
throw err;
|
||||
test.equal(res, "s2s foo");
|
||||
}));
|
||||
}
|
||||
]);
|
||||
})();
|
||||
|
||||
// XXX some things to test in greater detail:
|
||||
// staying in simulation mode
|
||||
// time warp
|
||||
|
||||
@@ -15,7 +15,7 @@ Package.on_use(function (api) {
|
||||
api.use('routepolicy', 'server');
|
||||
api.add_files(['sockjs-0.3.4.js',
|
||||
'stream_client_sockjs.js'], 'client');
|
||||
api.add_files('stream_client_nodejs.js', 'client');
|
||||
api.add_files('stream_client_nodejs.js', 'server');
|
||||
api.add_files('stream_server.js', 'server');
|
||||
|
||||
// livedata_connection.js uses a Minimongo collection internally to
|
||||
@@ -27,7 +27,7 @@ Package.on_use(function (api) {
|
||||
|
||||
api.add_files('livedata_common.js', ['client', 'server']);
|
||||
|
||||
api.add_files('livedata_connection.js', 'client');
|
||||
api.add_files('livedata_connection.js', ['client', 'server']);
|
||||
|
||||
api.add_files('livedata_server.js', 'server');
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ Meteor._DdpClientStream = function (endpoint) {
|
||||
status: "connecting", connected: false, retryCount: 0
|
||||
};
|
||||
|
||||
self.statusListeners = window.Deps && new Deps.Dependency;
|
||||
self.statusListeners = typeof Deps !== 'undefined' && new Deps.Dependency;
|
||||
self.statusChanged = function () {
|
||||
if (self.statusListeners)
|
||||
self.statusListeners.changed();
|
||||
@@ -73,6 +73,8 @@ _.extend(Meteor._DdpClientStream, {
|
||||
_endpointToUrl: function (endpoint) {
|
||||
// XXX should be secure!
|
||||
// among other problems
|
||||
endpoint = endpoint.replace(/^http(s)?:\/\//, "");
|
||||
endpoint = endpoint.replace(/\/$/, "");
|
||||
return 'ws://' + endpoint + '/websocket';
|
||||
}
|
||||
});
|
||||
@@ -200,7 +202,7 @@ _.extend(Meteor._DdpClientStream.prototype, {
|
||||
_cleanupConnection: function () {
|
||||
var self = this;
|
||||
|
||||
self.clearConnectionTimer();
|
||||
self._clearConnectionTimer();
|
||||
if (self.currentConnection) {
|
||||
self.currentConnection.close();
|
||||
self.currentConnection = null;
|
||||
@@ -236,6 +238,12 @@ _.extend(Meteor._DdpClientStream.prototype, {
|
||||
self.statusChanged();
|
||||
},
|
||||
|
||||
_lostConnection: function () {
|
||||
var self = this;
|
||||
self._cleanupConnection();
|
||||
self._retryLater();
|
||||
},
|
||||
|
||||
_retryTimeout: function (count) {
|
||||
var self = this;
|
||||
|
||||
@@ -288,6 +296,8 @@ _.extend(Meteor._DdpClientStream.prototype, {
|
||||
// launch a connect attempt. we have no way to track it. we either
|
||||
// get an _onConnect event, or we don't.
|
||||
|
||||
// XXX: set up a timeout on this.
|
||||
|
||||
// we would like to specify 'ddp' as the protocol here, but
|
||||
// unfortunately WebSocket-Node fails the handshake if we ask for
|
||||
// a protocol and the server doesn't send one back (and sockjs
|
||||
|
||||
Reference in New Issue
Block a user