无法连接到Firebase for Cloud Messaging

时间:2016-07-01 18:05:42

标签: node.js firebase google-cloud-messaging xmpp firebase-cloud-messaging

我正在尝试使用Node.js中的xmpp协议连接到Firebase云消息服务器(CCS)。到目前为止,我没有成功。

我正在使用node-xmpp-client库,它给出了以下错误:

{ [Error: connect ETIMEDOUT 64.233.191.188:5235]
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: '64.233.191.188',
  port: 5235 }

这是我的代码:

var Client = require('node-xmpp-client');

var client = new Client({
  jid:      '<my sender id>@gcm.googleapis.com',
  password: '<my server key>',
  host:     'fcm-xmpp.googleapis.com',
  port:     5235
});

client.connection.socket.on('error', function (error) {
  console.log("socket error");
  console.error(error);
  process.exit(1);
});

client.on('online', function (data) {
  console.log('Connected as ' + data.jid.local + '@' + data.jid.domain + '/' + data.jid.resource);
});

client.on('error', function (err) {
  console.log("server error");
  console.error(err);
  process.exit(1);
});

1 个答案:

答案 0 :(得分:0)

尝试使用Client.Client并添加legacySSl和preferredSaslMechanism

const XMPP = require('node-xmpp-client');
this._client = new XMPP.Client({
        jid: `${config.id}@gcm.googleapis.com`,
        password: config.key,
        port: config.port,
        host: config.host,
        legacySSL: true,
        preferredSaslMechanism: 'PLAIN'
      });

这对我有用