Nodejs XMPP Component Usage

1k Views Asked by At

I'm trying to create a nodejs component using node-xmpp-component. But I keep getting error code 400, type modify, bad request, but I don't see anything wrong with my iq message.

My ejabberd configuration:

{5282, ejabberd_service, [ 
    { hosts, ["nodejs.myejabberddomain"], [{password, "admin"}] } 
 ]}

My nodejs Component code:

var Component = require('node-xmpp-component')
  , ltx = require('node-xmpp-core').ltx;


var component = new Component({
  jid       : "nodejs.myejabberddomain",
  password  : "admin",
  host      : "localhost",
  port      : "5282"
})

component.on('online', function() {
    console.log('Component is online')

    var iq = new ltx.Element('iq',{type:'set',id:'reg2', to: 'myejabberddomain'})
                .c('query',{xmlns:'jabber:iq:register'});

    component.send(iq);

})

component.on('error', function(e) {
    console.error(e)
    process.exit(1)
})

I'm not sure if I have any ejabberd configuration missing, or if I have any problem with my nodejs component connection or if this nodejs-xmpp-component is "broken"!

Anyone knows what I'm doing wrong? Any tips?

3

There are 3 best solutions below

0
On BEST ANSWER

I've changed from ejabberd to prosody, but at first the registration was returning "service-unavailable".

So I had to go on prosody chat, and user called Zash helped me creating a module named mod_register_from_component.

In the lines 182 to 185 I changed the original mod_register to:

module:hook("iq/host/jabber:iq:register:query", function(event)
   local session, stanza = event.origin, event.stanza;

   if session.type ~= "component" then

Then in the prosody.cfg.lua in the modules_enabled I added my new module (and commented the original one)

2
On

From XEP-0114: Jabber Component Protocol:

Once authenticated, the component can send stanzas through the server and receive stanzas from the server. All stanzas sent to the server MUST possess a 'from' attribute and a 'to' attribute, as in the 'jabber:server' namespace. The domain identifier portion of the JID contained in the 'from' attribute MUST match the hostname of the component. However, this is the only restriction on 'from' addresses, and the component MAY send stanzas from any user at its hostname.

4
On

Using version 1.0.0-alpha1 I am able to sucessfully connect to a prosody server using your code above.

Do you receive your 'online' message? if so my suggestion would be that your ejabberd server doesn't support registering and is sending you an error response?