node-xmpp
XMPP library for node.js
node-xmpp xmpp for node.js
Title is fairly self explanatory. I need to create an XMPP server in Node.js to communicate with Google Cloud Messaging. The XMPP connection should allow me to send messages from the server to the client (Android app) and also from the app back to the server without the app needing a seperate socket connection to the server (all messages routed through GCM. Could anyone perhaps guide me in the right direction?
P.S. If I have provided insufficient information please let me know :)
Source: (StackOverflow)
I'm using node-xmpp using browserify for web application. When I try to make a for browser file using browserify, the resulting file outputs this in js console -
Cannot load StringPrep-0.1.0 bindings. You may need to npm install
node-stringprep
client.js:5108 Cannot load StringPrep-0.2.3 bindings
(using fallback). You may need to npm install node-stringprep
client.js:34 Cannot load StringPrep-0.2.3 bindings (using fallback).
You may need to npm install node-stringprep
After which the code fails saying
Uncaught TypeError: undefined is not a function
The file client.js work fine when i use in terminal
node client.js
There is nothing much in client.js
var xmpp = require('simple-xmpp');
xmpp.connect({
jid : 'loginid',
password : 'password',
host : 'localhost',
port : 5222
});
xmpp.on('online', function() {
console.log('Yes, I\'m connected!');
});
xmpp.on('chat', function(from, message) {
xmpp.send(from, 'echo: ' + message);
});
xmpp.on('error', function(err) {
console.error(err);
});
xmpp.on('subscribe', function(from) {
if (from === 'a.friend@gmail.com') {
xmpp.acceptSubscription(from);
}
});
which I simply took from their documentation. Any pointers ??
Source: (StackOverflow)
I'm trying to learn and understand how XMPP works.
As I understand it, node-xmpp-bosh is a connection manager. A connection manager is not a full blown xmpp server, but sort of acts like a proxy, and forwards the xmpp requests on to a dedicated xmpp server. This results in saving the dedicated xmpp server some of the load it would usually undertake in handling connections - Though I'm not fully sure how this results in savings, or why there's such an overhead in handling connections.
I've been provided with an OpenFire xmpp server to connect to, but this resides on a different domain to my web application. I've decided to use node-xmpp-bosh as a proxy to get around the XSS issues that would result, and this should also allow me to use websockets with a BOSH fallback for older browsers.
I'm trying to use the Strophe.js library in my client application to send the actual messages.
How do I configure node-xmpp-bosh to forward the requests on to the actual xmpp server? The documentation doesn't make this very clear, so I presume it's only forwarding requests to an xmpp server on the same machine that hosts the connection manager. Also, do I need to configure Strophe differently in order to use a connection manager, or do I simply send the request to the connection manager, and this should send it on for me.
Many thanks in advance
Source: (StackOverflow)
I'm looking at 'XEP-0077 in-band registration' about how to register a new XMPP account. Here is my code. I use node-xmpp to connect my node.js application to an ejabberd server.
var net = require('net');
var xmpp = require('node-xmpp');
var cache = new Object();
net.createServer( function(socket) {
socket.setEncoding('utf8');
socket.addListener('data',function(data) {
data = data.substr(0,data.length-2);
if(cache.admin==undefined && data=='login') {
var ejabberd =new xmpp.Client({jid:"admin@mine",password:'12345',host:'192.168.7.202',port:'5222'});
cache.admin = ejabberd;
cache.admin.addListener('online',function() {
cache.admin.send(new xmpp.Element('presence',{type:'chat'}).c('show').c('status').t('mine status'));
cache.admin.send(new xmpp.Element('iq',{type:'get',id:'reg1'}).c('query',{xmlns:'jabber:iq:register'}));
})
cache.admin.addListener('stanza',function(stanza) {
if(stanza.is('iq')) {
console.log(stanza.children[1]);
}
})
cache.admin.addListener('end',function() {
cache.admin.end();
cache.admin = undefined;
})
}
if(cache.admin!=undefined && data=='logout') {
cache.admin.end();
cache.admin = undefined;
} else if(cache.admin!=undefined && data=='register') {
cache.admin.send(new xmpp.Element('iq',{type:'set',id:'reg1'}).c('query',{xmlns:'jabber:iq:register'}).c('username').t('alow').up().c('password').t('test'));
}
});
}).listen(5000);
If i run this code, I get this error:
{ name: 'error',
parent:
{ name: 'iq',
parent: null,
attrs:
{ from: 'admin@mine',
to: 'admin@mine/20108892991316770090454637',
id: 'reg1',
type: 'error',
xmlns: 'jabber:client',
'xmlns:stream': 'http://etherx.jabber.org/streams' },
children: [ [Object], [Circular] ] },
attrs: { code: '403', type: 'auth' },
children:
[ { name: '**forbidden**',
parent: [Circular],
attrs: [Object],
children: [] } ] }
In 'XEP-0077: In-Band Registration' it says that the forbidden
reason means that "The sender does not have sufficient permissions to cancel the registration".
How can I get such permissions?
Source: (StackOverflow)
Does anyone have an updated guide for installing node-xmpp from start to finish on either Cent OS or Ubuntu's latest builds?
I have attempted installing but continue to get the following error:
Cannot load StringPrep-0.1.0 bindings. You may need to `npm install node-stringprep'
This is the log for stringprep:
root@node-xmpp:~/node-latest-install# npm install node-stringprep
npm http GET https://registry.npmjs.org/node-stringprep
npm http 200 https://registry.npmjs.org/node-stringprep
npm http GET https://registry.npmjs.org/node-stringprep/-/node-stringprep-0.1.5.tgz
npm http 200 https://registry.npmjs.org/node-stringprep/-/node-stringprep-0.1.5.tgz
> node-stringprep@0.1.5 install /root/node-latest-install/node_modules/node-stringprep
> node-gyp rebuild
make: Entering directory `/root/node-latest-install/node_modules/node-stringprep/build'
CXX(target) Release/obj.target/node-stringprep/node-stringprep.o
SOLINK_MODULE(target) Release/obj.target/node-stringprep.node
SOLINK_MODULE(target) Release/obj.target/node-stringprep.node: Finished
COPY Release/node-stringprep.node
make: Leaving directory `/root/node-latest-install/node_modules/node-stringprep/build'
node-stringprep@0.1.5 node_modules/node-stringprep
Source: (StackOverflow)
I'm having trouble understanding how to retrieve an XMPP roster (and eventually the presence state of each contact) in node-xmpp (GTalk account).
My example code can login and connect, but I'm a bit lost as to what to send and listen for:
var xmpp = require('node-xmpp')
jid = 'example@gmail.com'
password = 'xxxxxxxxxxxxxx'
// Establish a connection
var conn = new xmpp.Client({
jid: jid,
password: password,
host: 'talk.google.com',
port: 5222
})
conn.on('online', function() {
console.log('ONLINE')
var roster = new xmpp.Element('iq', {
type: 'get',
from: jid,
id: new Date().getTime()
}).c('query', { xmlns: 'jabber:iq:roster' })
conn.send(roster) // Now what?
})
conn.on('error', function(e) {
console.log(e)
})
Source: (StackOverflow)
I'm using the node-xmpp module to connect to a XMPP server and join a group chat. Connecting to the server, setting the presence, joining the room and reading out messages works so far. But I want to receive the userlist of the room too.
The XMPP protocol requires to send a presence stanza when the client enters the room (http://xmpp.org/extensions/xep-0045.html#enter-pres). But how can I now parse it in node?
My code currently looks like this:
var xmpp = require('node-xmpp');
// Create the XMPP Client
var cl = new xmpp.Client({
jid: jid,
password: password,
reconnect: true
});
// Do things when online
cl.on('online', function() {
util.log("We're online!");
// Set client's presence
cl.send(new xmpp.Element('presence', { type: 'available' }).c('show').t('chat'));
cl.send(new xmpp.Element('presence', { to: room_jid+'/'+room_nick }).c('x', { xmlns: 'http://jabber.org/protocol/muc' }).c('history', {seconds: 1}));
// Send keepalive
setInterval(function() {
cl.send(' ');
}, 30000);
cl.on('stanza', function(stanza) {
// always log error stanzas
if (stanza.attrs.type == 'error') {
util.log('[error] ' + stanza);
return;
}
// ignore everything that isn't a room message
if (!stanza.is('message') || !stanza.attrs.type == 'chat') {
return;
}
var body = stanza.getChild('body');
// message without body is probably a topic change
if (!body) {
return;
}
// Extract username
var from, room, _ref;
_ref = stanza.attrs.from.split('/'), room = _ref[0], from = _ref[1];
var message = body.getText();
// Log topics and messages to the console
if(!from) {
util.log('Topic: ' + message);
} else {
util.log('[' + from + ']: ' + message);
}
});
});
I already tried triggering presence by using
if(stanza.is('presence')) {}
within the cl.on('stanza') part but it doesn't work.
Source: (StackOverflow)
I have implemented a nodejs xmpp server. As a client i have pidgin. I can't send messages from pidgin to server. Why? I can connect and authentication works.
This is my server code:
'use strict'
var xmpp = require('../index')
, server = null
, Client = require('node-xmpp-client')
var startServer = function(done) {
// Sets up the server.
server = new xmpp.C2S.TCPServer({
port: 5222,
domain: 'localhost'
})
// On connection event. When a client connects.
server.on('connection', function(client) {
// That's the way you add mods to a given server.
// Allows the developer to register the jid against anything they want
client.on('register', function(opts, cb) {
console.log('REGISTER')
cb({code: 'foo', type: 'bar'})
})
// Allows the developer to authenticate users against anything they want.
client.on('authenticate', function(opts, cb) {
console.log('server:', opts.username, opts.password, 'AUTHENTICATING')
if (opts.password === 'secret') {
console.log('server:', opts.username, 'AUTH OK')
cb(null, opts)
}
else {
console.log('server:', opts.username, 'AUTH FAIL')
cb(false)
}
})
client.on('online', function() {
console.log('server:', client.jid.local, 'ONLINE')
client.send(new xmpp.Element('iq', { type: 'chat', 'xml:lang': 'ko' }).c('body').t('Welcome to server!'))
})
// Stanza handling
client.on('stanza', function(stanza) {
console.log('server:', client.jid.local, 'stanza', stanza.toString())
//var from = stanza.attrs.from
//stanza.attrs.from = stanza.attrs.to
//stanza.attrs.to = from
console.log(stanza.toString());
client.send(stanza.toString())
//console.log('Stanza sent is :'+stanza);
})
// On Disconnect event. When a client disconnects
client.on('disconnect', function() {
console.log('server:', client.jid.local, 'DISCONNECT')
})
})
server.on('listening', done)
}
startServer(function() {
})
Source: (StackOverflow)
I am using node-xmpp library to communicate with ejabberd server installed on ubuntu.
I have the following script to register and perform actions in the server..
var xmpp = require("node-xmpp");
var c2s = new xmpp.C2SServer({
port: 5223,
domain: 'domain.com'
});
c2s.on('connect', function(client) {
console.log('connect ??? ++++++++');
c2s.on('register', function(opts, cb) {
console.log('REGISTER')
cb(true)
})
client.on('authenticate', function(opts, cb) {
console.log('AUTH' + opts.jid + ' -> ' +opts.password)
cb(null) // cb(false)
})
client.on('disconnect', function() {
console.log('DISCONNECT')
})
});
I am able to see the connect message in the server. But its not invoking the register event.
However i have another ejabberd instance in 5222 port which is working fine for registration from Audium XMPP Client.
Source: (StackOverflow)
Can I use customs auth mechanisms in node-xmpp without forking it? I need to auth with mechanism very similar to X-OAUTH2, but with other title and simpler auth() method( see code for more information).
Source: (StackOverflow)
I'm having an issue with node-xmpp, server-side settings out of my control maybe have changed but this error is relatively new. Looking for some pointers/insight, I've not been able to solve this issue within the module or my code. I unfortunately cannot provide my code to troubleshoot, however, it's on the simple xmpp.Client/send method. It's failing about 80% of the time is the kicker.
Thanks
Cannot read property 'write' of undefined
at lib/node/.npm/ltx/0.0.5/package/lib/element.js:197:22
at Array.forEach (native)
at Element.write (lib/node/.npm/ltx/0.0.5/package/lib/element.js:196:23)
at lib/node/.npm/ltx/0.0.5/package/lib/element.js:198:23
at Array.forEach (native)
at Element.write (lib/node/.npm/ltx/0.0.5/package/lib/element.js:196:23)
at lib/node/.npm/ltx/0.0.5/package/lib/element.js:198:23
at Array.forEach (native)
at Element.write (lib/node/.npm/ltx/0.0.5/package/lib/element.js:196:23)
at Client.send (lib/node/.npm/node-
xmpp/0.2.10/package/lib/xmpp/connection.js:76:12)
Here's the source from connection.js in question:
Connection.prototype.send = function(stanza) {
if (!this.socket.writable) {
this.socket.end();
return;
}
if (stanza.root) {
var el = this.rmStreamNs(stanza.root());
var socket = this.socket;
el.write(function(s) { socket.write(s); }); // LINE 76
return el;
} else {
this.socket.write(stanza);
return stanza;
}
};
Source: (StackOverflow)
how to use node-xmpp to receive message from client...?
i already known how to sent message
here the sample code how to send message...
var net = require("net");
var xmpp = require('node-xmpp');
var server = net.createServer(
function(socket) {
socket.setEncoding("utf8");
socket.on('data',function(data) {
chat(data,socket);
});
}
);
server.listen(3000);
var chat = function(data,socket) {
var cl = new xmpp.Client({ jid: 'admin@mine',password: '12345' });
cl.on('online',
function() {
cl.send(new xmpp.Element('message',
{ to: 'test@mine',
type: 'chat'}).
c('body').
t(data));
// nodejs has nothing left to do and will exit
cl.end();
});
}
Source: (StackOverflow)
How to connect to a Jabber conference? Send and receive messages. Get a list of online users.
Source: (StackOverflow)