Wrox Programmer Forums
| 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 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 June 25th, 2014, 08:01 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
Cool How to handle joining a chat room

I've been splitting hairs, trying to accomplish what I though would be simple and straight forward (writing a handler which triggers an action once a user joins a chat room).

So here's the line for joining the chat room
Code:
My_namespace.connection.send(
			
$pres({to:  My_namespace.room_jid + "/" + My_namespace.nick, id: "join_room"}).c("jid").t(My_namespace.jid).up().c("nick").t(My_namespace.nick)
			
);
And here is the line that sets the handler before initial presence is sent

Code:
My_namespace.connection.addHandler(My_namespace.room_joined, null, "presence", null, "join_room");

And here's the handler implementation

Code:
		My_namespace.room_joined = function(presence){
	
		
			var nick = $(presence).children("nick").text();
			
			var jid = $(presence).children("jid").text();
		
                        console.log("Successfully joined room.  Nick is: "+nick+" and jid is: "+jid );

			return true;
		
		}

This doesn't work. I suspected that you cannot use ids with such stanzas. So i stripped the id attribute and tried this instead, similar to what's in the book

Code:
		My_namespace.room_joined = function(presence){


			var from = $(presence).attr("from");
			
			
			if(from === My_namespace.room_jid + "/" + My_namespace.nick){//If presence is coming from me
				
			     var nick = $(presence).children("nick").text();
			
			     var jid = $(presence).children("jid").text();
		
                        console.log("Successfully joined room.  Nick is: "+nick+" and jid is: "+jid );

                        }


			return true;
		
		}
This kind of works, but only when I test it on the iPhone. For some reason I do not understand, it either won't run on a pc or mac, or it just takes for ever to trigger the handler. Who knows how to best go about this?




Similar Threads
Thread Thread Starter Forum Replies Last Post
Chat Room aliusmankhan ASP.NET 2.0 Professional 2 August 23rd, 2008 07:51 AM
GUI chat room mralam Java GUI 4 October 30th, 2007 04:46 AM
Online Chat Room pro-logic .NET Web Services 0 October 20th, 2003 05:26 AM
Chat Room Creation HELP! nvillare Classic ASP Basics 2 August 28th, 2003 06:46 AM
Chat Room Trouble nvillare Classic ASP Basics 0 July 11th, 2003 03:58 PM





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