1

I'm new to node.js and XMPP but not Javascript or GCM. I'm unable to receive upstream messages using node-xmpp and none of the callbacks are called, not even error. I've looked through the other SO threads but none of the solutions have worked. Here is my entire route:

var express = require('express');
var router = express.Router();
var xmpp = require('node-xmpp');

router.get('/', function(req, res, next) {

  var options = {
    type: 'client',
    jid: 'project-12345@gcm.googleapis.com',
    password: 'apiKey12345',
    port: 5235,
    host: 'gcm.googleapis.com',
    legacySSL: true,
    preferredSaslMechanism : 'PLAIN'
  };

  // this prints correctly
  console.log('Creating xmpp app');

  var cl = new xmpp.Client(options);
  cl.connection.socket.setTimeout(0);
  cl.connection.socket.setKeepAlive(true, 10000);

  // None of these callbacks are called
  cl.on('online', function() {
    console.log('online');
  });

  cl.on('connection', function() {
    console.log('online');
  });

  cl.on('authenticate', function(opts, cb) {
    console.log('authenticated');
  });

  cl.on('error',function(e) {
    console.error(e);
  });

  cl.on('stanza', function(stanza) {
    console.log(stanza);
  });

  res.render('index', { title: 'GCM upstream test' });
});

module.exports = router;

Thanks

Nick
  • 45
  • 4
  • 1
    There are two problems: 1) You are running the XMPP Client inside express.js server which means the XMPP client socket will only get initialized after you make a request to / , not after you start the server. 2) I've tested without express.js and the code in node-xmpp-client doesn't work. I've tried to run DEBUG=xmpp:client:session,xmpp:client node ccs.js to get some logging/debugging out of the library, but only got "Creating xmpp app xmpp:client:session start socket connection +0ms", then I've sent an upstream message from the app but on the server I see nothing. – Alex Bitek Jun 15 '15 at 12:47
  • I think http://stackoverflow.com/questions/22566024/cant-connect-to-gcm-using-node-xmpp-client is a related question. You have to debug the node-xmpp-client library and determine what's the problem. – Alex Bitek Jun 15 '15 at 12:52

1 Answers1

0

OP here: The issue was because the route was terminating the XMPP action upon reaching res.render. Upon removing the XMPP code from the route, I get an XMPP authentication failure, which is most likely due to an incorrect jid/password. The project requirements have changed and I no longer need upstream messaging, so I will not attempt to fix the auth failure. Thanks for the responses

Nick
  • 45
  • 4