node-xmpp-client not sending simple message

595 Views Asked by At

i'm new to node.js.

I'm following the code from here.

I tried to implement node-xmpp-client here. My simple project code is:

'use strict'

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



var client = new Client({jid: '<project_id>@gcm.googleapis.com', password: <api_key>, port: 5235,  host: 'gcm.googleapis.com', legacySSL: true, preferredSaslMechanism: 'PLAIN'})

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

client.on('online', function (data) {
    var stanza = new Client.Stanza('message', {to: '<reg_id of a client>', type: 'chat'});
    console.log(stanza);
    client.send(stanza);


  client.end()
})

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

my stanza output is:

Stanza {
    name: 'message',
    parent: null,
    children: [],
    attrs: 
        { to: '<reg_id of client>', type: 'chat' }
}

why my messae is not deliever to the client?

0

There are 0 best solutions below