oortcloud / node-ddp-client

A callback style DDP (Meteor's Distributed Data Protocol) node client.
Other
263 stars 80 forks source link

ddpclient connect and call not working with faye-websocket > 0.7.2 #43

Closed shrop closed 9 years ago

shrop commented 10 years ago

I have a node server which makes ddp client connections to push data from a Drupal installation to a Meteor app. Been working great until some fellow devs installed newer version of the ddp client.

Node server using ddp-client: http://cgit.drupalcode.org/spectacle/tree/modules/spectacle_core/ddp.js

When I install ddp@0.8.1, the default dependencies are (these do not work for me): faye-websocket@0.7.3 └── websocket-driver@0.3.6

I am not able to get the ddp server above to work unless I use the dependency versions below: faye-websocket@0.7.2 └── websocket-driver@0.3.5

The package.json file we are having to use to make things work for now: http://cgit.drupalcode.org/spectacle/tree/modules/spectacle_core/package.json

Any thoughts on what is going on or how to debug further. Glad to help. :) Thanks!

emgee3 commented 10 years ago

If you specify the faye-websocket and websocket-driver versions manually (as you have done in the package.json), the 0.8.1 version of ddp version should use them without issue.

It sounds more like one of the changes I did in 0.8.0 is unintentionally a breaking change. Would you mind to try changing lines 8-15 of your ddp.js to:

var ddpclient = new DDPClient({
  maintainCollections: false
});

and see if that makes a difference. I did find one bug (fixed here). The above snippet should bypass it.

shrop commented 10 years ago

Yes, we were able to pin faye-websocket and websocket-driver versions manually and we are now running ddp version 0.8.1. That works for us as you expected it to.

We made your code changes in lines 8-15 with all the latest version of the ddp-client and dependencies and it did not work.

Can continue to test if you have ideas. Thanks for the quick response!

emgee3 commented 10 years ago

With the updated ddp.js, you mind unpinning the faye-websockets and websocket-driver?

shrop commented 10 years ago

Sure. I tested with the following module versions and with the ddp.js updated to what I have below:


ddp@0.8.1 node_modules/ddp
├── ddp-ejson@0.8.1-3
├── ddp-underscore-patched@0.8.1-2
└── faye-websocket@0.7.3 (websocket-driver@0.3.6)

var ddpclient = new DDPClient({
  maintainCollections: false
});

This setup did not work. We are still able to successfully connect and work with ddp using the following versions and your suggested ddpclient setup above:


├─┬ ddp@0.7.0
│ ├── ddp-ejson@0.8.1-3
│ └── ddp-underscore-patched@0.8.1-2
├── faye-websocket@0.7.2
└── websocket-driver@0.3.5
emgee3 commented 10 years ago

Ok, so we isolated the change to something the websocket driver, though I don't know what else to say without digging deeply into that code.

However, by rearranging your code a bit, I'm able to get it to work:

// Setup server to respond to Drupal post submissions.
var express = require('express');
var bodyParser = require('body-parser');
var DDPClient = require("ddp");

var app = express();

var ddpclient = new DDPClient({
  // host: "localhost",
  // port: 3000,
  // autoReconnect: true,
  // autoReconnectTimer: 500,
  // ssl: false,
  maintainCollections: false
});

app.use(bodyParser.json());

// Setup routes for our nodejs listener.
app.get('/', function(req, res) {
  res.send('Ready for Spectacle connection!');
});

app.post('/', function(req, res, next) {
  console.log(req.headers);
  console.log(req.body);

  ddpclient.call(
    'addPost',
    [req.body]
  );

  res.send({ status: 'SUCCESS' });
});

ddpclient.connect(function(err) {
  if (err) throw new Error('DDP connection error!');
  console.log('connected!');
});

// Nodejs listener setup for port 8080.
app.listen(8080);
console.log('Listening for data on port: 8080');

// Monitor ddp connection for messags (for debugging purposes).
ddpclient.on('message', function (msg) {
  console.log("ddp message: " + msg);
});
emgee3 commented 9 years ago

Feel free to reopen as needed.