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 April 16th, 2010, 02:22 PM
Authorized User
 
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Thumbs up "type" attribute missing in $pres() responce

Hello.

I'm having a problem in chapter 6. (page 115)

on_presence: function (presence) {

var ptype = $(presence).attr('type');
var from = $(presence).attr('from');

........
........

}

The problem is, presence Object does not have any "type" attribute at all, neither any of my roster presence info (only mine). Here's a response:

HTML Code:
<body xmlns="http://jabber.org/protocol/httpbind">
<presence to="my_login@domain/c04d8f71" from="my_login@adomain/9e42b46e"></presence>
</body>
I've successfully retrieved my roster above. I have mutual subscriptions.
I'm using openFire server with build-in BOSH support.
  #2 (permalink)  
Old April 16th, 2010, 03:47 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

You didn't mention how the code fails. The 'type' attribute is not required, so it's ok if the type is missing. A missing 'type' on a presence stanza can be interpreted as "available".

Is this causing the code to fail, or were you just curious why this attribute was missing?
  #3 (permalink)  
Old April 16th, 2010, 04:45 PM
Authorized User
 
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by metajack View Post
were you just curious why this attribute was missing?
Exactly! code runs smoothly, I'm confused since, on_presence (initial page 115 version) is meant to retrieve presence values for "me" and all of my contacts (I might be misunderstanding the point though).

I've expected something like one presence response for corresponding contact, plus one for "me". Instead I'm getting several responses for "me" with different "resource" values, with no "type" attribute. What results in "offline" presence.

When running the script I knew for sure, none of my contacts were online. Could this be an essential factor ?

Thanx for replying!
  #4 (permalink)  
Old April 17th, 2010, 07:23 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

You will get one presence stanza for yourself for each connected resource. It sounds like you have some other connected resources that are still hanging around.

This can happen if a BOSH session isn't terminated cleanly (like if you force-reload the page and don't have any onunload handlers to end the session). These will be timed out after 60-120 seconds.

Offline presence is signified with a type attribute set to 'unavailable'. No type attribute signifies 'available'. The reason is that available presence stanzas are the most common stanzas sent in XMPP, so it is prudent to optimized their size by not having an attribute as opposed to including a type attribute set to 'available'.

Does that clear things up?
  #5 (permalink)  
Old April 19th, 2010, 01:30 PM
Authorized User
 
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanx, now almost everything seem to be clear ! except one thing:

When page is reloaded, "Connection." is being disconnected automatically. "on_presence" handler informs, user went offline. I could reinsure it's really true, by checking server's admin panel. That's nice.

But when pressing disconnect button (manually triggers "Connection.disconnect()"), "Strophe.Status" goes to "disconnecting" followed by "disconnected", that's seem to be ok, but "on_presence" handler is "silent", server's admin panel indicates user's still online.

Tested in Firefox + Firebug, in two firefox windows, with two user accounts. Both goes online, first keeps listening for second's presence, second's trying to reload/disconnect.

Last edited by senpai; April 19th, 2010 at 01:48 PM..
  #6 (permalink)  
Old April 19th, 2010, 03:35 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

In the case where sending disconnect didn't result in the user going offline, was this the only connected resource for that user? A user will only go offline no resources are currently available.
  #7 (permalink)  
Old April 19th, 2010, 07:04 PM
Authorized User
 
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default

it looks like one resource per connection.

I've played a bit with js code, adding "Connection.disconnect()" anywhere directly in js code does the job well. I guest it works just because disconnect is triggered just after connection is made.

Assigning "click" event to an HTML element, behaves differently, page loads, "long-time-pulling" POST request starts (not sure how to call it), clicking to "disconnect" button finally changes Strophe status to "disconnected", though FireBug is not happy with it, showing up "bad request red style" message with code "Aborted". User stays online
  #8 (permalink)  
Old April 19th, 2010, 07:09 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

If you could post the code, I'm sure I could help you spot the error.
  #9 (permalink)  
Old April 19th, 2010, 08:31 PM
Authorized User
 
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Here's modified version to localize the problem

HTML Code:
     <button id="button-login">Login</button>
     <button id="button-disconnect">Disconnect</button>

     <script type="text/javascript">

       $(function() {
            
           // global object  
           Jabber = new Jabber('domain.com');
		
		$('#button-login').click(function () {
			Jabber.connect('dude', 'password');
		})

		$('#button-disconnect').click(function () {
			Jabber.disconnectAction();
	        })
          });
      </script>

PHP Code:
function Jabber(domain) {

    
this.Connection null;
    
this.jid '';
    
    
this.domain domain;
    
this.server 'http://' this.domain '/jabber';
}

Jabber.prototype.connect = function(loginpassword) {

    
Jabber.Connection = new Strophe.Connection(Jabber.server);
    
    
Jabber.jid login '@' Jabber.domain;
    
Jabber.Connection.connect(Jabber.jidpassword, function(status) {
        
        if (
status == Strophe.Status.CONNECTED) {    
            
Jabber.presenceAction();
        }
        else if (
status == Strophe.Status.DISCONNECTED) {
            
Jabber.Connection null;
        }    
    });
}

Jabber.prototype.presenceAction = function() {
    
    var 
stanza $pres();
    
Jabber.Connection.send(stanza);
}

Jabber.prototype.disconnectAction = function() {

    if (
Jabber.Connection) {
        
Jabber.Connection.disconnect();
    }

  #10 (permalink)  
Old April 20th, 2010, 12:31 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

The code looks fine. Each time this code connects, the server will assign you a random resource. Each time you connect, a different random resource will be assigned.

This means that if you don't cleanly disconnect your session, the BOSH connection manager will keep it open until it times out (usually around 60-90 seconds). If you reconnect while the old session is still alive, and then disconnect, you will still be online until the old session times out.

One way to avoid getting a new resource every time is to specify one to connect(). Try
Code:
Jabber.jid = login + "@" + Jabber.domain + "/Jabber";
That will either not let you connect while the other session is alive, or it will kick off the old session (depends on server configuration).

Another thing to do is wait to test until the user goes offline. If your code isn't connected, and the user is online, waiting a few minutes should fix the issue. The BOSH connection manager will time out the connection.

Let me know if either of those helps.
 


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
How to theme the "Browse" button of "FileUpload" control? varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 14th, 2009 01:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Chap 11: "Properties" function missing tomche BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 May 24th, 2009 09:12 AM
MasterPage Attribute alink "Outdated?" Psyclist BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 March 28th, 2009 05:04 AM



All times are GMT -4. The time now is 02:38 PM.


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