Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > BOOK: Professional XMPP Programming with JavaScript and jQuery
|
BOOK: Professional XMPP Programming with JavaScript and jQuery
This is the forum to discuss the Wrox book Professional XMPP Programming with JavaScript and jQuery by Jack Moffitt; ISBN: 978-0-470-54071-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional XMPP Programming with JavaScript and jQuery section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 30th, 2013, 09:14 PM
Authorized User
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default Message stanza sent to bare jid not being received

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', {

                                
jidNs.jid,

                                
passwordNs.jpassword

                        
});//End connect to xmpp

              
});//End button click function


//And the connect function

        
$(document).bind('connect', function (evdata) {


                var 
conn = new Strophe.Connection(

                    
"http://bosh.metajack.im:5280/xmpp-httpbind");


                
conn.connect(data.jiddata.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_functionnull"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({

                        
toto,

                        
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?
 
Old August 30th, 2013, 09:43 PM
Wrox Author
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

There are two reasons I can think of:

1) You didn't send initial presence or sent invisible presence, etc. It sounds like you know about this and checked for it.

2) If your message receive handler crashes or doesn't return "true" then it will be removed and won't get called for more messages. Maybe the barejid is causing it to crash?
 
Old August 30th, 2013, 10:02 PM
Authorized User
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What's the difference between invisible presence and regular presence?
 
Old August 31st, 2013, 11:06 AM
Wrox Author
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

Presence priority -1 I think. Or perhaps it's type=invisible.
 
Old August 31st, 2013, 11:26 AM
Authorized User
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Now I can have multiple devices with the same priority value right?
 
Old August 31st, 2013, 11:58 AM
Wrox Author
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

Yes. There's no issue at all with multiple resources with the same priority.
 
Old August 31st, 2013, 01:12 PM
Authorized User
 
Join Date: May 2013
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Turns out the problem was I had to include the to attribute and assign a priority in the presence stanza. What's weird is that for weeks, the $pres() build method worked just fine without any attributes.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Can one assign a jid resource of their choosing? drayarms BOOK: Professional XMPP Programming with JavaScript and jQuery 5 August 8th, 2013 01:20 PM
Can't figure out how to handle incoming message stanza drayarms BOOK: Professional XMPP Programming with JavaScript and jQuery 6 June 3rd, 2013 01:14 AM
XMPP performance on using common jid sudhansu BOOK: Professional XMPP Programming with JavaScript and jQuery 4 November 26th, 2012 12:41 AM
Bare JID & too many resources tiracu BOOK: Professional XMPP Programming with JavaScript and jQuery 1 September 21st, 2010 06:39 PM
Message received by "FILE" adapter is suspended skindika Biztalk 0 February 2nd, 2009 07:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.