 |
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
|
|
|
|

April 16th, 2010, 02:22 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
"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.
|
|

April 16th, 2010, 03:47 PM
|
|
Wrox Author
|
|
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
|
|
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?
|
|

April 16th, 2010, 04:45 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by metajack
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!
|
|

April 17th, 2010, 07:23 PM
|
|
Wrox Author
|
|
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
|
|
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?
|
|

April 19th, 2010, 01:30 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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..
|
|

April 19th, 2010, 03:35 PM
|
|
Wrox Author
|
|
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
|
|
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.
|
|

April 19th, 2010, 07:04 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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 
|
|

April 19th, 2010, 07:09 PM
|
|
Wrox Author
|
|
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
|
|
If you could post the code, I'm sure I could help you spot the error.
|
|

April 19th, 2010, 08:31 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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(login, password) {
Jabber.Connection = new Strophe.Connection(Jabber.server); Jabber.jid = login + '@' + Jabber.domain; Jabber.Connection.connect(Jabber.jid, password, 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(); } }
|
|

April 20th, 2010, 12:31 PM
|
|
Wrox Author
|
|
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
|
|
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.
|
|
 |