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 November 11th, 2012, 05:38 PM
Authorized User
 
Join Date: Nov 2012
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default xmpp is not always updated with new incoming messages

I am doing the one to one chat by referring ch06 example.

Test Case1: logged in as two user as UserA and UserB. UserA send first message , it is successfully received and shown in UserB but if again UserA sends another messges it is not showing.

Any urgent help will be great.

****************Code**********
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="author" content="Provident BV" />
	<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/cupertino/jquery-ui.css" />
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
	<script src="scripts/strophe/strophe.js"></script>
	<script src="scripts/flXHR.js"></script>
	<script src="scripts/strophe/plugins/strophe.flxhr.js"></script>
	<link rel="stylesheet" href="css/hello.css" />
	
	<title>XMPP</title>
	<script>
	var Arthur = {
connection: null,
handle_message: function (message) {
	
var full_jid = $(message).attr('from');
alert(full_jid);
var uname  = Strophe.getNodeFromJid(full_jid);

var body1 = $(message).find('body');
		if (body1.length > 0) {
			body1 = body1.text();
		} else {
			body1 = null;
		}
var div = $("<div></div>");
body1 = uname+': '+body1;
div.append(body1);
div.prependTo('#stream');
}
};
	
$(document).ready(function () {
$('#login_dialog').dialog({
autoOpen: true,
draggable: false,
modal: true,
title: 'Connect to XMPP',
buttons: {
"Connect": function () {
$(document).trigger('connect', {
jid: $('#jid').val(),
password: $('#password').val()
});
$('#password').val('');
var hidval = $('#jid').val();
$('#hid_jid').val(hidval);
var uname1 = hidval.split('@');
alert(uname1[0]);
if(uname1[0]=='hapina'){
	$("#userID").text("Start chat with swati");
	var sendval = "swati@desktop";
	$('#send_jid').val(sendval);
}else{
	$("#userID").text("Start chat with hapina");
	var sendval = "hapina@desktop";
	$('#send_jid').val(sendval);
}
$(this).dialog('close');
}
}
});
$('#input').keyup(function () {
var left = 140 - $(this).val().length;
$('#counter .count').text('' + left);
});
$('#input').keypress(function (ev) {
if (ev.which === 13) {
ev.preventDefault();
var text = $(this).val();
$(this).val('');
var sendjid = $('#send_jid').val();
var ownjid = $('#hid_jid').val();

if(sendjid==ownjid){
	$(document).trigger('disconnected');	
}
var msg = $msg({to: sendjid, type: 'chat'})
.c('body').t(text);
alert(msg);
Arthur.connection.send(msg);
}
});
});
$(document).bind('connect', function (ev, data) {
var conn = new Strophe.Connection(
'http://localhost/bosh');

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');
}
});
Arthur.connection = conn;
});
$(document).bind('connected', function () {
	
Arthur.connection.addHandler(Arthur.handle_message,
null, "message", "chat");

//var presence = $pres().c("show").t("away").up()
//.c("status").t("Off to Meryton");
Arthur.connection.send($pres());
});
$(document).bind('disconnected', function () {
	Arthur.connection = null;
   

    $('#login_dialog').dialog('open');
});

	</script>
</head>

<body>

<h1>Hello</h1>
<span id="userID"></span>
<input type="hidden" id="send_jid" /></br>
<textarea id='input' rows='3'></textarea>
<input type="hidden" id="hid_jid" />
<div id='counter'><span class='count'>140</span> chars left</div>
<div id='stream'>
</div>
<!-- login dialog -->
<div id="login_dialog" class="hidden">
<label>JID:</label>
<input type="text" id="jid" />

<label>Password:</label><input type="password" id="password" />
</div>

</body>
</html>
 
Old November 11th, 2012, 07:55 PM
Wrox Author
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

I'll need the wire logs of what is getting sent and received over the XMPP connection. See the examples in Chapter 4 for how to produce those (rawInput()/rawOutput).
 
Old November 12th, 2012, 04:32 AM
Authorized User
 
Join Date: Nov 2012
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Below are the raw inputs.

1. UserA Sends the below message to UserB
<message to='[email protected]' type='chat' xmlns='jabber:client'><body>dd</body></message>

2. UserB is able to recieve the message body and show out put as "dd".

3. Again UserA sends the below message to UserB
<message to='[email protected]' type='chat' xmlns='jabber:client'><body>ssss</body></message>

4.But this time UserB does not recieve any thing.


I did some change to send you the actual rawinput.

******Below is raw input which UserA([email protected]/5180c0a5) sends to UserB ([email protected])*****************

<stream:features>
<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
<mechanism>
DIGEST-MD5
</mechanism>
<mechanism>
PLAIN
</mechanism>
<mechanism>
ANONYMOUS
</mechanism>
<mechanism>
CRAM-MD5
</mechanism>
</mechanisms>
<compression xmlns='http://jabber.org/features/compress'>
<method>
zlib
</method>
</compression>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
</stream:features>
<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'
mechanism='DIGEST-MD5'/>
<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
cmVhbG09IndlYjA2LnByb3ZpZGVudC5ubCIsbm9uY2U9Ii8rV3 doMzlkdHdZWWdUOXZWN2VzcE5sbkJJVWw2QXJ0ZUZIQ3I4a2Ii LHFvcD0iYXV0aCIsY2hhcnNldD11dGYtOCxhbGdvcml0aG09bW Q1LXNlc3M=
</challenge>
<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
dXNlcm5hbWU9InN1ZGhhbnN1IixyZWFsbT0id2ViMDYucHJvdm lkZW50Lm5sIixub25jZT0iLytXd2gzOWR0d1lZZ1Q5dlY3ZXNw TmxuQklVbDZBcnRlRkhDcjhrYiIsY25vbmNlPSI4MjM1MWYwMj NlMzczYjRlMmMyZGE4MzI3NWQ5NGYzMiIsbmM9IjAwMDAwMDAx Iixxb3A9ImF1dGgiLGRpZ2VzdC11cmk9InhtcHAvd2ViMDYucH JvdmlkZW50Lm5sIixyZXNwb25zZT0iYzBkZTU1MThlZjU5MGVk MDFlOWE4NzQwMGMzZDZjOTIiLGNoYXJzZXQ9InV0Zi04Ig==
</response>
<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
cnNwYXV0aD1jNGJiOWRlYjRjYzdjM2JmNjU0NzI0MWE2Y2M4M2 Q4NQ==
</success>
<stream:features>
<compression xmlns='http://jabber.org/features/compress'>
<method>
zlib
</method>
</compression>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
</stream:features>
<iq type='set'
id='_bind_auth_2'
xmlns='jabber:client'>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
</iq>
<iq xmlns='jabber:client'
type='result'
id='_bind_auth_2'
to='web06.provident.nl/5180c0a5'>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
<jid>
[email protected]/5180c0a5
</jid>
</bind>
</iq>
<iq type='set'
id='_session_auth_2'
xmlns='jabber:client'>
<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
</iq>
<iq xmlns='jabber:client'
type='result'
id='_session_auth_2'
to='[email protected]/5180c0a5'/>
<presence xmlns='jabber:client'/>
<presence xmlns='jabber:client'
from='[email protected]/cf69898'
to='[email protected]'/>
<message to='[email protected]'
type='chat'
xmlns='jabber:client'>
<body>
ss
</body>
</message>
<message to='[email protected]'
type='chat'
xmlns='jabber:client'>
<body>
ff
</body>
</message>
<message to='[email protected]'
type='chat'
xmlns='jabber:client'>
<body>
gg
</body>
</message>
<message to='[email protected]'
type='chat'
xmlns='jabber:client'>
<body>
gh
</body>
</message>
<message to='[email protected]'
type='chat'
xmlns='jabber:client'>
<body>
1
</body>
</message>
<message to='[email protected]'
type='chat'
xmlns='jabber:client'>
<body>
2
</body>
</message>
<message to='[email protected]'
type='chat'
xmlns='jabber:client'>
<body>
3
</body>
</message>
<message to='[email protected]'
type='chat'
xmlns='jabber:client'>
<body>
4
</body>
</message>


******Below is raw input which UserB ([email protected]) recieves*****************


<stream:features>
<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
<mechanism>
DIGEST-MD5
</mechanism>
<mechanism>
PLAIN
</mechanism>
<mechanism>
ANONYMOUS
</mechanism>
<mechanism>
CRAM-MD5
</mechanism>
</mechanisms>
<compression xmlns='http://jabber.org/features/compress'>
<method>
zlib
</method>
</compression>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
</stream:features>
<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'
mechanism='DIGEST-MD5'/>
<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
cmVhbG09IndlYjA2LnByb3ZpZGVudC5ubCIsbm9uY2U9IlhidT UxaEwxZndxNWRsQlB3OHdGOU13VmQ3L2VjQk1yUVpSU0QvOUIi LHFvcD0iYXV0aCIsY2hhcnNldD11dGYtOCxhbGdvcml0aG09bW Q1LXNlc3M=
</challenge>
<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
dXNlcm5hbWU9ImpvaGFuIixyZWFsbT0id2ViMDYucHJvdmlkZW 50Lm5sIixub25jZT0iWGJ1NTFoTDFmd3E1ZGxCUHc4d0Y5TXdW ZDcvZWNCTXJRWlJTRC85QiIsY25vbmNlPSJhNmRiMTNmNDM4Nj E1NjFkOTQwMjIwMjc5YWRiOTQ1YSIsbmM9IjAwMDAwMDAxIixx b3A9ImF1dGgiLGRpZ2VzdC11cmk9InhtcHAvd2ViMDYucHJvdm lkZW50Lm5sIixyZXNwb25zZT0iNTEyZjEyYjBhOGIxNGUyZGY4 YzgyNTFkMzU4YWUwMjIiLGNoYXJzZXQ9InV0Zi04Ig==
</response>
<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
cnNwYXV0aD0yNDNmYTdiZjI2ODJhYTc0OGFmZmViYTBhYjBjMj dhOA==
</success>
<stream:features>
<compression xmlns='http://jabber.org/features/compress'>
<method>
zlib
</method>
</compression>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
</stream:features>
<iq type='set'
id='_bind_auth_2'
xmlns='jabber:client'>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
</iq>
<iq xmlns='jabber:client'
type='result'
id='_bind_auth_2'
to='web06.provident.nl/cf69898'>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
<jid>
[email protected]/cf69898
</jid>
</bind>
</iq>
<iq type='set'
id='_session_auth_2'
xmlns='jabber:client'>
<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
</iq>
<iq xmlns='jabber:client'
type='result'
id='_session_auth_2'
to='[email protected]/cf69898'/>
<presence xmlns='jabber:client'/>
<presence xmlns='jabber:client'
from='[email protected]/5180c0a5'
to='[email protected]/cf69898'/>
<message xmlns='jabber:client'
to='[email protected]'
type='chat'
from='[email protected]/5180c0a5'>
<body>
ss
</body>
</message>
<message xmlns='jabber:client'
to='[email protected]'
type='chat'
from='[email protected]/5180c0a5'>
<body>
ff
</body>
</message>
<message xmlns='jabber:client'
to='[email protected]'
type='chat'
from='[email protected]/5180c0a5'>
<body>
gg
</body>
</message>
<message xmlns='jabber:client'
to='[email protected]'
type='chat'
from='[email protected]/5180c0a5'>
<body>
gh
</body>
</message>
<message xmlns='jabber:client'
to='[email protected]'
type='chat'
from='[email protected]/5180c0a5'>
<body>
1
</body>
</message>
<message xmlns='jabber:client'
to='[email protected]'
type='chat'
from='[email protected]/5180c0a5'>
<body>
2
</body>
</message>
<message xmlns='jabber:client'
to='[email protected]'
type='chat'
from='[email protected]/5180c0a5'>
<body>
3
</body>
</message>
<message xmlns='jabber:client'
to='[email protected]'
type='chat'
from='[email protected]/5180c0a5'>
<body>
4
</body>
</message>


By executing the CH4 i am getting this output and it seems that the message packets are not lost and received properly. But I am not able understand why the below is not working.

var full_jid = $(message).attr('from');
alert(full_jid);
var uname = Strophe.getNodeFromJid(full_jid);

var body1 = $(message).find('body');


Please help me in this case as it is very urgent to me.

Last edited by sudhansu; November 12th, 2012 at 06:30 AM..
 
Old November 12th, 2012, 10:57 AM
Wrox Author
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

Your handle_message isn't returning true. If it doesn't return true it is removed from the handler list after it processes that event.

The messages are being received, it's just that your handler isn't called anymore after the first one. Add 'return true;' to the end of your handler and it should work as you expect.
 
Old November 12th, 2012, 03:29 PM
Authorized User
 
Join Date: Nov 2012
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

First of all many thanks for your help , it seems to be working. Also kindly can you let me know how we can show offline messages, and time stamp of each message when it was send.

Thanks
 
Old November 12th, 2012, 04:09 PM
Wrox Author
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

Glad it's working now.

Offline messages will get sent with a delayed delivery tag. You can read more about those here:
http://xmpp.org/protocols/urn_xmpp_delay/
 
Old November 12th, 2012, 04:41 PM
Authorized User
 
Join Date: Nov 2012
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is that delayed tag will be formed automatically by XMPP or we have to send it explicitly. Also please let me know how we can get the time stamp while receiving a message.

Thanks
 
Old November 12th, 2012, 04:45 PM
Wrox Author
 
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
Default

The delayed tag is automatically added by the server's offline message processing.

You can pull out the timestamp just as you would any other XML data. $(msg).find('delay').attr('stamp') for example.
 
Old November 13th, 2012, 03:18 PM
Authorized User
 
Join Date: Nov 2012
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is there any way where I can also see the time stamp of normal messgaes rather than just for offline messages?

Means can I do something like $(msg).find('body').attr('stamp')
 
Old November 14th, 2012, 03:32 PM
Authorized User
 
Join Date: Nov 2012
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am new to xmpp so any help to my above question will be very helpful for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
File transfer using jingle in XMPP Purushotham BOOK: Professional XMPP Programming with JavaScript and jQuery 2 February 17th, 2015 07:25 AM
Openfire and xmpp:restart sarahgt BOOK: Professional XMPP Programming with JavaScript and jQuery 1 February 5th, 2012 08:10 PM
Establishing XMPP connection badinar BOOK: Professional XMPP Programming with JavaScript and jQuery 0 January 20th, 2011 06:27 PM
XMPP server authentication badinar BOOK: Professional XMPP Programming with JavaScript and jQuery 1 January 17th, 2011 01:50 PM
What about NoSQL over xmpp? flossy BOOK: Professional XMPP Programming with JavaScript and jQuery 2 June 28th, 2010 02:22 PM





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