So I have 2 browsers running, both with the same page. In this page you can log into the server with an account.
The connection is build with Strophe. And everything is HTML and javascript.
Now I already managed to build a chat (between the 2 browsers, each logged in with a different user). And this is working perfectly.
What I want to achieve now is to send an IQ to one user from the other. Both saying in the status bar that they are receiving the IQ (one as a ‘got the request’, the other as ‘got the result’)
Now, I create my iq with:
var iq = $iq({type: 'get', to: this.receiver}).c('query', {xmlns: 'http://jabber.org/protocol/pubsub#retrieve-subscriptions'});
XmppObject.xmpp.connection.sendIQ(iq);
This is set in a function that can be called by the press of a button.
The listener is build as follow:
$(XmppObject.xmpp).bind("iq", function(event, data){
addToStatus('Received an iq: \n');
handlePong(data.iq);
});
With handlePong as:
function handlePong(msg)
{
var objMsg = $(msg);
var from = objMsg.attr('from');
var type = objMsg.attr('type');
var id = objMsg.attr('id');
var text = 'Received iq from ' + from + ' with id ' + id + ' and type ' + type + '\n\n';
addToStatus(text);
}
Now when client1 sends an IQ to client2 this is the result:
Client1:
Received iq from client2@domain with id pingPong and type result
Client2:
Now is there a way to display in the status of client2 that he got the initial request?
You will need to:
iqwith you own namespace, you cannot just simply recycle the existing ones. It will work, but it’s plain wrong.addHandleron the connection.The simplest example I can find doing exactly that is the
pingimplementation of strophe plugins, see https://github.com/metajack/strophejs-plugins/blob/master/ping/strophe.ping.js