Unable to receive upstream GCM messages with Node.js + XMPP

490 views Asked by At

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: '[email protected]',
    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

1

There are 1 answers

0
Nick On BEST ANSWER

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