0 Replies Latest reply on May 13, 2014 3:34 PM by Dele Olajide

    Sample Openfire External Component with NodeJs plugin

    Dele Olajide

      Here is a simple xmpp component that echos every message using the xmppjs module

       

       

      var jid = "echo", password = "your_password";
      var xmpp = require("../xmpp");
      var conn = new xmpp.Connection("your_domain");
      var sys = require("sys");
      var id = 1;
      
      
      conn.log = function (_, m) { sys.puts(m); };
      
      
      conn.connect(jid, password, function (status, condition) 
      {
                if(status == xmpp.Status.CONNECTED)
                {
                          conn.addHandler(onMessage, null, 'message', null, null,  null);
      
                          setInterval(function()
                          {
                                    id++;
      
                                    conn.send(xmpp.iq({from: jid + "." + conn.host, to: conn.host, id: "iq:" + id, type: "get"}).c("ping", {xmlns: 'urn:xmpp:ping'}));
      
                          }, 60000);
                } else
                          conn.log(xmpp.LogLevel.DEBUG, "New connection status: " + status + (condition?(" ("+condition+")"):""));
      });
      
      
      function onMessage(message) {
                conn.send(xmpp.message({
                          to:message.getAttribute("from"),
                          from:message.getAttribute("to"),
                          type: "chat"})
                                    .c("body").t(message.getChild("body").getText()));
      }
      
      
      
      

       

       

      Create two new properties below and unzip the attached file into /opt/openfire/nodejs or wherever your OPENFIRE_HOME folder is.

       

      property nameproperty value
      js.xmppjs.echo.path/opt/openfire/nodejs/xmppjs
      js.xmppjs.echoexamples/echo.js