openfire - Strophe Ping Plugin Not responding -


i trying add strophe ping plugin in ping user , respond pong, , know user connected.

but not sure how working.

i read in documentation example, isnt working me.

i want form of call saying other person connected.

   conn.addhandler(pinghandler, "urn:xmpp:ping", "iq", "get");    function pinghandler(ping) {  var pingid = ping.getattribute("1");  var = ping.getattribute("from");  var = ping.getattribute("to");  var pong = $iq({type: "result", "to": from, id: pingid, "from": to});  conn.send(pong);   return true; }     

i tried method below, method below send out ping , called success sent, there no respond in pinghandler. seems sent, not listened to/handled.

  conn.ping.addpinghandler( pinghandler );     function onping(){       var jid3="test4@macbook-pro.local"        console.log("ping starts"); conn.ping.ping( jid3, success, error, timeout );        function success(){      console.log("ping sent");       }        function error(){      console.log("ping not sent");       }        function timeout(){      console.log("ping timeout");       }       }               function pinghandler(ping) {                   console.log("pong back");      var pingid = ping.getattribute("id");      var =  ping.getattribute("from");      var = ping.getattribute("to");      var pong = $iq({type: "result", "to": from, id: pingid, "from": to});      conn.send(pong);       return true;     }  

edit

sent: <body rid='4132220829' xmlns='http://jabber.org/protocol/httpbind' sid='a7411f98'><iq type='get' to='test4sdfsdfs@macbook-pro.local' id='1:ping' xmlns='jabber:client'><ping xmlns='urn:xmpp:ping'/></iq></body>  recv: <body xmlns='http://jabber.org/protocol/httpbind' ack='4132220829'/>  recv: <body xmlns='http://jabber.org/protocol/httpbind' ack='4132220829'><iq xmlns='jabber:client' type='result' id='1:ping' from='test4sdfsdfs@macbook-pro.local' to='test3@macbook-pro.local/a7411f98'/></body> 

you need attach ping listener/handler upon connecting sends pong. listener responds pings sent you. ping sender sets handler handle pong.

var onconn = function(){     conn.ping.addpinghandler(onping); };  var onping = function (iq) {     conn.ping.pong(iq);     return true; };  var onpong = function(iq){     //do whatever response     return false; };  var sendping = function(jid){     conn.ping.ping(         jid,         function (iq) {onpong(iq);},         function () { console.log('failed!'); },          3000); };  sendping('foo@jabberservername.com'); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -