Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > BOOK: Professional XMPP Programming with JavaScript and jQuery
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 30th, 2013, 09:14 PM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
  #2 (permalink)  
Old August 30th, 2013, 09:43 PM
Wrox Author
Points: 702, Level: 10
Points: 702, Level: 10 Points: 702, Level: 10 Points: 702, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
  #3 (permalink)  
Old August 30th, 2013, 10:02 PM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
  #4 (permalink)  
Old August 31st, 2013, 11:06 AM
Wrox Author
Points: 702, Level: 10
Points: 702, Level: 10 Points: 702, Level: 10 Points: 702, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
  #5 (permalink)  
Old August 31st, 2013, 11:26 AM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
  #6 (permalink)  
Old August 31st, 2013, 11:58 AM
Wrox Author
Points: 702, Level: 10
Points: 702, Level: 10 Points: 702, Level: 10 Points: 702, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
  #7 (permalink)  
Old August 31st, 2013, 01:12 PM
Authorized User
Points: 182, Level: 3
Points: 182, Level: 3 Points: 182, Level: 3 Points: 182, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:52 AM.


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