Example #1
0
 on_online(conn, function(){    
     var room_iq = new xmpp.Element('iq', { to: room_jid + "@muc." + nconf.get("account:jid").split("@")[1], type: 'set' })
             .c("query", { xmlns : 'http://jabber.org/protocol/muc#owner'})
             .c("destroy");
 
     console.log("Destroying room...");
     conn.send(new xmpp.Element("presence", { type: "available" }).c("show").t("chat")); 
     conn.send(room_iq);
     
     cb();
     conn.end();
 });
Example #2
0
 on_online(conn, function(){    
     var room_iq = new xmpp.Element('iq', { to: room_jid + "@muc." + nconf.get("account:jid").split("@")[1], type: 'set' })
             .c("query", { xmlns : 'http://jabber.org/protocol/muc#admin'})
             .c("item", { nick : participant, role : "participant"})
             .c("reason")
             .t("violated rules");
 
     console.log("Kicking a user in a room...");
     conn.send(room_iq);
     
     cb();
     conn.end();
 });
Example #3
0
module.exports = exports = function (config) {
  bot = new xmpp.Client(config);

  bot.on("online", echoPresence);
  bot.on("stanza", saveTicket);
  bot.on("error", errorHandle);

  queue_helper.enableBot(sendTicket);

  bot.on("disconnect", queue_helper.disableBot);

  return bot;
};
	var connect = function() {
		
		//Open up our XMPP connection
		conn = new xmpp.Client(settings.jabber.client);
		
		conn.on('online', function () {
			set_status_message(settings.jabber.status_message);
			
			if(typeof settings.onlineCallback === 'function')
			{
				settings.onlineCallback();
			}
			
		});
		
		conn.on('stanza', function (stanza) {
			util.log(stanza);
	
			//subscription request
			if (stanza.is('presence') && stanza.attrs.type === 'subscribe' && settings.jabber.allow_auto_subscribe) {
				var subscribe_elem = new xmpp.Element('presence', {
						to : stanza.attrs.from,
						type : 'subscribed'
					});
				conn.send(subscribe_elem);
			}
	
			//messages
			if ('error' === stanza.attrs.type) {
				util.log('[error] ' + stanza.toString());
			} else if (stanza.is('message')) {
				util.log('[message] RECV: ' + stanza.getChildText('body'));
				
				//there is a callback to pass the message to
				if(typeof settings.messageCallback === 'function')
				{
					settings.messageCallback({
						from: stanza.attrs.from,
						type: stanza.attrs.type,
						body: stanza.getChildText('body')
					});					
				}
				
			}
	
		});
		
	}
Example #5
0
 conn.on("stanza", function(stanza){
     if (stanza.is("iq")){
         var query = stanza.getChild("query").getChildren("item");
         
         var i = 0,
             array_users = [],
             array_msgs = [];
             
         query.forEach(function(q){
             array_users.push({
                 "name" : q.attrs.name
             });
         });
         
         cb(JSON.stringify(array_users));
         conn.end();
     };
     
     if (stanza.is("message") && stanza.attrs.type == "groupchat"){
         var msg_body = stanza.getChild("body");
         console.log(msg_body);
         /*
         msg_body.forEach(function(q){
             array_msgs.push({
                 "msg" : q.attrs.name
             });
         });
         */
     }
 });
Example #6
0
exports.create_room = function(room_jid, room_name, room_desc, cb){
    var conn = new xmpp.Client(nconf.get("account")); 
    on_online(conn, function(){
        var room_presence = new xmpp.Element("presence", { 
            to: room_jid + "@muc." + nconf.get("account:jid").split("@")[1] + "/" + (nconf.get("account:jid")).split("@")[0] 
        }).c('x', { xmlns: 'http://jabber.org/protocol/muc' });
        
        var room_iq = new xmpp.Element('iq', { to: room_jid + "@muc." + nconf.get("account:jid").split("@")[1], type: 'set' })
                .c("query", { xmlns : 'http://jabber.org/protocol/muc#owner'})
                .c("x", { xmlns:"jabber:x:data", type:"submit" });
                
        room_iq.c("field", { "var":'muc#roomconfig_roomname' })
               .c("value")
               .t(room_name);
               
       room_iq.c("field", { "var":'muc#roomconfig_roomdesc' })
              .c("value")
              .t(room_desc);
        
        console.log("Creating room...");
        conn.send(new xmpp.Element("presence", { type: "available" }).c("show").t("chat")); 
        // Send new room's presence
        conn.send(room_presence);
        // Set room's name
        conn.send(room_iq);
        
        cb();
        conn.end();
    });
}
 cl.on('online', function() {
     console.log('connected to jabber...')
     cl.send(new xmpp.Element('presence', { })
       .c('show').t('chat').up()
       .c('status').t('Send a song name')
     )
 })
Example #8
0
cl.addListener('online', function(data) {

  // inform the user
  console.log(
    'Connected as ' + data.jid.user +
    '@' + data.jid.domain + '/' +
     data.jid.resource
  );

  // iterate over all JIDs
  argv.slice(5).forEach(function(to) {

    // create a new XML message with ltx (a xml library)
    var stanza = new xmpp.Element(
      'message', { to: to, type: 'chat' }
    ).c('body').t(argv[4])

    // stanza.toString() would result into something linke this:
    //
    // <message to='*****@*****.**' type='chat>
    //   <body>The message text</body>
    // </message>

    // send the message
    cl.send(stanza);
  });

  // close the connection
  cl.end();

  // nodejs has nothing left to do and will exit
})
Example #9
0
function subscribeToJID(jid){
    var subscribeElem = new xmpp.Element('presence', {
        to: jid,
        type: 'subscribed'
    });
    conn.send(subscribeElem);
}
Example #10
0
 this.sendMessage = function(to, msg) {
   var elem = new xmpp.Element('message', {
     to: to,
     type: 'chat'
   }).c('body').t(msg);
   client.send(elem);
 };
Example #11
0
exports.discover_rooms = function(cb){
    var conn = new xmpp.Client(nconf.get("account"));
    on_online(conn, function(){
        var room_iq = new xmpp.Element('iq', { to: "muc." + nconf.get("account:jid").split("@")[1], type: 'get' })
                .c("query", { xmlns : 'http://jabber.org/protocol/disco#items'});
    
        console.log("Discovering rooms...");
        conn.send(new xmpp.Element("presence", { type: "available" }).c("show").t("chat")); 
        conn.send(room_iq);
        
        conn.on("stanza", function(stanza){
            console.log("STANZA " + stanza);
            if (stanza.is("iq")){
                var query = stanza.getChild("query").getChildren("item");
                
                var i = 0;
                var array = [];
                query.forEach(function(q){
                    array.push({
                        "jid" : q.attrs.jid,
                        "name" : q.attrs.name
                    });
                });
                cb(JSON.stringify(array));
                conn.end();
            }
        });
        
        conn.on("error", function(stanza){
            console.log("[ERROR] ")
        });
    });
}
 function() {
   xmpp_bot.send(
     new xmpp.Element('presence', { }).
     c('show').t('chat').up().
     c('status').t('Partychat to IRC gateway. send messages back and forth')
   );
   irc_bot.say(config.irc_channel,'Logged into Jabber as '+ config.jid);
 });
  button.on('down', function() {
    // create and send the message
    var stanza = new xmpp.Element('message',
        { to: recv_jabber_user, type: 'chat' }
    ).c('body').t(a_message);

    cl.send(stanza);
  });
Example #14
0
        conn.on('online', function(){
            conn.send(new xmpp.Element('presence'));
			// +JOIN
			conn.send(new xmpp.Element('presence', {type: 'available'}).c('show').t('chat'))
			var roster_query = new xmpp.Element('iq', {type: 'get', id: (new Date()).getTime()}).c('query', {xmlns: 'jabber:iq:roster'})
			// conn.send(roster_query)
			// /+JOIN
            events.emit('online');
            $.start();
            //make the connection live 
            setInterval(function() {
				// +JOIN
               conn.send(new xmpp.Element('presence'));
				// conn.send(roster_query)
				// /+JOIN
            }, 1000 * 10)
        });
Example #15
0
function xmppAppender(config, layout) {
    var loggingEvents = [],
        client = new xmpp.Client(config.client);

    layout = layout || layouts.messagePassThroughLayout;

    function send(body) {
        var stanza;

        if (body) {
            stanza = new xmpp.Element(
                'message',
                {
                    to: config.to,
                    type: 'chat'
                }
            ).c('body').t(body);

            client.send(stanza);
        }
    }

    client.addListener('online', function (data) {
        var body;

        console.log('XMPP client is connected as ' + data.jid.user + '@' +
                    data.jid.domain + '/' + data.jid.resource);

        body = loggingEvents.map(layout).join('\n');
        loggingEvents = null;
        send(body);
    });

    client.addListener('error', function (e) {
        console.error('XMPP client encountered error, ' + e);
    });

    return function (loggingEvent) {
        if (loggingEvents) {
            loggingEvents.push(loggingEvent);
        } else {
            send(layout(loggingEvent));
        }
    };
}
Example #16
0
 var acceptSubscriptionRequests = function(stanza) {
   if (stanza.is('presence') && stanza.attrs.type === 'subscribe') {
     var subscribeElem = new xmpp.Element('presence', {
       to: stanza.attrs.from,
       type: 'subscribed'
     });
     client.send(subscribeElem);
   }
 };
Example #17
0
  it("send message", function (done) {
    svcl.once('stanza', function (stanza) {
      stanza.is('message').should.be.true;
      stanza.attrs.to.should.eql("*****@*****.**");
      done();
    });

    cl.send(new xmpp.Message({to: '*****@*****.**'}).c('body').t('hi'));
  });
Example #18
0
 function connect() {
   client = new XMPP.Client(_connectionString);
   client.on("error", handleError);
   client.on("online", handleOnline);
   client.on("stanza", handleStanza);
   client.on("offline", handleOffline);
   client.on("connect", handleConnect);
   client.on("reconnect", handleReconnect);
   client.on("disconnect", handleDisconnect);
   log.debug("[HARMONY] connect.");
 }
Example #19
0
cl.on('online', function() {
	cl.send(new xmpp.Message({ type: 'chat' }).c('body').t("Hello there from " + UUID));
	util.log("We're online!");
 
	// set ourselves as online
	cl.send(new xmpp.Element('presence', { type: 'available' }).
		c('show').t('chat')
		);
 
	// join room (and request no chat history)
	cl.send(new xmpp.Element('presence', { to: room_jid+'/'+room_nick }).
		c('x', { xmlns: 'http://jabber.org/protocol/muc' })
		);
 
	// send keepalive data or server will disconnect us after 150s of inactivity
	setInterval(function() {
		cl.send(new xmpp.Message({ type: 'chat' }).c('body').t(UUID + " Checking in."));
	    }, 15000);
    });
FacebookChat.prototype.connect = function() {
	var self = this;
	
	var client = new xmpp.Client({
		jid: utils.buildUserId(this.settings.userID),
		api_key: this.settings.appId,
		access_token: this.settings.accessToken,
		host: 'chat.facebook.com'
	});

	client.addListener('online', function () {
		self.connected = true;
		self.emit('connected');
	});
	this.client = client;

	this._bindError();
	this._bindStanza();
};
Example #21
0
socket.on("connection", function(connection) {
 var client = new xmpp.Client({jid: "test@localhost", password: ""});
 client.on("online", function() {
  client.send(new xmpp.Element("presence", {type: "chat"}));
  client.send(new xmpp.Element("message", {to: "alagu@localhost", type: "chat"}).c("body").t("Testing"));
  connection.on("message", function(message) {
   client.send(new xmpp.Element("message", {to: "alagu@localhost", type: "chat"}).c("body").t(message));
  });
  connection.on("disconnect", function() {
   client.end();
  });
 });
 client.on("stanza", function(stanza) {
  if (stanza.is("message")) {
   var b = stanza.getChildren("body");
   if (b[0]) connection.send(b[0].getText());
  }
 });
});
Example #22
0
        'send': function(contact, message, callback) {
            var user = contact[1] + '@' + contact[2]; // lol

            client.send(new nxmpp.Element('message', { 
                'to': user,
                'type': 'chat'
            }).c('body').t(message));

            callback();
        }
        conn.on('online', function(){
            if(! config.skipPresence) {
                conn.send(new xmpp.Element('presence'));
            }
            events.emit('online');
            $.start();

            // keepalive
            self.conn.connection.socket.setTimeout(0);
            self.conn.connection.socket.setKeepAlive(true, 10000);
        });
Example #24
0
    return this.makePromise(function(resolve, reject) {

      this.client.on('stanza', function onStanza(stanza) {
        if (stanza.attrs.id != data.attrs.id) return;
        this.client.removeListener('stanza', onStanza);

        console.log("<-- ", stanza.toString());

        if (stanza.attrs.type == 'error') {
          reject(new Error("Error response " + stanza));
          return;
        }

        resolve(stanza);
      }.bind(this));

      console.log("--> ", data.toString());
      this.client.send(data);

    });
Example #25
0
 conn.on('online', function(){
     if(! config.skipPresence) {
         conn.send(new xmpp.Element('presence'));
     }
     events.emit('online');
     $.start();
     // Use whitespace keepalives to keep the connection up
     setInterval(function() {
        conn.send(' ');
     }, 1000 * 60);
 });
Example #26
0
cl.addListener('error', function(e) {

  // log the error
  console.error(e);

  // close the connection
  cl.end();

  // and exit
  process.exit(1);
});
Example #27
0
function requestGoogleRoster(){
    console.log("Get Roster");   
    var rosterElem = new xmpp.Element('iq', { 
                                from: conn.jid,
                                type: 'get',
                                id: 'google-roster'
                            }).c('query', {
                                xmlns: 'jabber:iq:roster',
                                'xmlns:gr': 'google:roster',
                                'gr:ext': '2' 
                            });
    conn.send(rosterElem);
}
Example #28
0
 var requestGoogleRoster = function() {
   var rosterElem = new xmpp.Element('iq', {
     from: conn.jid,
     type: 'get',
     id: 'google-roster'
   })
     .c('query', {
       xmlns: 'jabber:iq:roster',
       'xmlns:gr': 'google:roster',
       'gr:ext': '2'
     });
   client.send(rosterElem);
 };
board.on("ready", function() {
  // create a piezo object (pin 3)
  var piezo = new five.Piezo(3);
  // connect to jabber
  var cl = new xmpp.Client({ jid: jabber_user,  password: jabber_password });

  board.repl.inject({
    piezo: piezo
  });

  // when connected to jabber, log to console, set presence to online
  cl.on('online', function() {
      console.log('connected to jabber...')
      cl.send(new xmpp.Element('presence', { })
        .c('show').t('chat').up()
        .c('status').t('Send a song name')
      )
  })

  // listen for msgs, play songs
  cl.addListener('stanza', function(stanza) {
      if (stanza.is('message') && (stanza.attrs.type !== 'error')) {
        var body = stanza.getChild('body');

        if (!body) {
          return;
        }

        var songTitle = body.getText();
        // play a song if it exists
        if (songTable[songTitle]) {
          piezo.song(songTable[songTitle]['notes'], songTable[songTitle]['durations']);
        }
        else {
          return;
        }
      }
  });
});
Example #30
0
 on_online(conn, function(){
     var room_iq = new xmpp.Element('iq', { to: room_jid + "@muc." + nconf.get("account:jid").split("@")[1], type: 'get' })
             .c("query", { xmlns : 'http://jabber.org/protocol/disco#items'});
 
     //console.log("Getting member list...");
     conn.send(room_iq);
     
     conn.on("stanza", function(stanza){
         if (stanza.is("iq")){
             var query = stanza.getChild("query").getChildren("item");
             
             var i = 0,
                 array_users = [],
                 array_msgs = [];
                 
             query.forEach(function(q){
                 array_users.push({
                     "name" : q.attrs.name
                 });
             });
             
             cb(JSON.stringify(array_users));
             conn.end();
         };
         
         if (stanza.is("message") && stanza.attrs.type == "groupchat"){
             var msg_body = stanza.getChild("body");
             console.log(msg_body);
             /*
             msg_body.forEach(function(q){
                 array_msgs.push({
                     "msg" : q.attrs.name
                 });
             });
             */
         }
     });
 });