I've been working on this application and all of a sudden, without having changed anything in my files to the best of my knowledge, all my message stanzas stopped working. All but one. On investigating, I realized that the one that did work was addressed to a specified full jid and not to the bare jid which i use throughout the application, the bare jid in this case being my jabber id username. When I replaced the "to" attribute of any of the stanzas that didn't work with the full jid of any one of my connected devices, lo and behold, the stanza worked. This is weird because I though that any device connected through my bare jid, would receive stanzas addressed to my bare jid as long as they sent available presence to the server. Let me include a simplified version of the code I'm working with.
PHP Code:
//Create the namespace for the app
var Ns = {
jid: "my_jabber_id",
jpassword:"my_jabber_password"
}
//This click event below is meant to trigger a connection to XMPP, and then send a message to all devices connected to my full jid
$(document).ready(function(){
$(".button").click(function(e){
//Trigger the connect to xmpp function which encapsulates the jid and password in its second argument which is then passed to bind connect function
$(document).trigger('connect', {
jid: Ns.jid,
password: Ns.jpassword
});//End connect to xmpp
});//End button click function
//And the connect function
$(document).bind('connect', function (ev, data) {
var conn = new Strophe.Connection(
"http://bosh.metajack.im:5280/xmpp-httpbind");
conn.connect(data.jid, data.password, function (status) {
if (status === Strophe.Status.CONNECTED) {
$(document).trigger('connected');
} else if (status === Strophe.Status.DISCONNECTED) {
$(document).trigger('disconnected');
}
});
Ns.connection = conn; //Bundle up the newly created instance of the strophe connection into this var which will be used to send ping and handle pong
});//End documend bind connect function
//And now the connected method
$(document).bind('connected', function () {//Upon successfull connection
//Get relevant jids
Ns.full_jid = Ns.connection.jid;
Ns.bare_jid = Strophe.getBareJidFromJid(Ns.connection.jid);
//Add all handlers that will receive ping stanzas at this stage before calling the pings
Ns.addHandler(Ns.pong_function, null, "message", "normal", "ping_stanza_id");
//Send presence to server once handler has been setup
Ns.connection.send($pres());
//Send a message stanza to full jid.
Ns.ping_function(Ns.full_jid);
//Well if the above line is replaced with Ns.bare_jid, the message isn't recieved by my application, but it is rather sent to my pidgin IM client installed on my machine
//Finally, here is the ping and pong function
Ns.ping_function = function (to) {
var send_details = $msg({
to: to,
type: "normal",
id: "ping_stanza_id"}).c("body").t("hohoho");
Ns.connection.send(send_details);
}//End ping function
Ns.get_pong_function = function (message) {
var msg = $(message).children('body').text();
$("#some_div").append(msg);
return true;
}//End pong function
});//End document ready
Well why won't the full jid work?