Wildfire, Spark and Smack

Any luck?

Im afraid I don’‘t understand Cold Fusion so I don’'t know how much help I can be.

Thanks,

Alex

andrewm1986 wrote:

I am happy to give you the exact ColdFusion code I am using. Please PM me with your email address or some other place to provide the code.

– hi Andrew,

I wrote up my experience with Smack / ColdFusion a couple years ago:

Instant Messenging with ColdFusion, Jabber and Smack | Aaron Johnson smack/

Take a look at that to see if you’‘re on the same track… otherwise, feel free to post the ColdFusion code here as part of a message. I’'d be more than happy to take a look at it.

AJ

Hi AJ,

It was your code I actually messed with to get it working how I wanted Great article!

Application.cfm

<cfapplication name=“cfjab” sessionmanagement=“Yes” sessiontimeout=“30”>

<cfset xmmpserver=“gis-mx-test”>

<cffunction name=“CFDUMP” returntype=“boolean” output=“yes”>

<cfargument name=“structure” type=“any”

default=“nothing to output”>

<CFDUMP Var="#arguments.structure#">

<cfreturn true>

</cffunction>

frame.cfm

<cfscript>

// if no connection exists, create one

if (NOT structKeyExists(session, “connection”)) {

session.XMPPConnection = createObject(“java”, “org.jivesoftware.smack.XMPPConnection”).init(xmmpserver);

session.XMPPConnection.connect();

session.username = GetAuthUser();

// login to the jabber server

try {

login = Session.XMPPConnection.login(session.username, “password”);

} catch (any excpt) {

accounts = Session.XMPPConnection.getAccountManager();

accounts.createAccount(session.username, “password”);

Session.XMPPConnection = createObject(“java”, “org.jivesoftware.smack.XMPPConnection”).init(xmmpserver);

session.XMPPConnection.connect();

login = Session.XMPPConnection.login(session.username, “password”);

}

session.operator = getOperator(Session.XMPPConnection);

//cfdump(session);

count = 0;

// WriteOutput(getUserStatus(session.operator, Session.XMPPConnection));

// WriteOutput("<BR>") ;

while ((getUserStatus(session.operator, Session.XMPPConnection)) NEQ “Online”) {

session.operator = getOperator(Session.XMPPConnection);

count = count + 1;

if (count GT 100) {

writeoutput(“Error : No avalible operators found!”);

abort();

}

// WriteOutput(getUserStatus(session.operator, Session.XMPPConnection));

// WriteOutput("<BR>") ;

}

// create a chat w/ another user

chat = Session.XMPPConnection.createChat(session.operator & “@” & xmmpserver);

// store the connection and chat objects in session scope

session.connection = Session.XMPPConnection;

session.chat = chat;

// init an empty string to hold the conversation

session.conversation = “”;

session.messages = ArrayNew(1);

newmessage = StructNew();

newmessage.text = "Your operator is " & session.operator;

ArrayAppend(session.messages, newmessage);

//writeoutput("<META HTTP-EQUIV=’‘Refresh’’ CONTENT=’‘1’’>");

//writeoutput("Your Operator Is " & session.operator & “<BR>”);

} else {

// write the conversation to the screen

writeoutput("<html><head><title></title>");

// writeoutput("<META HTTP-EQUIV=’‘Refresh’’ CONTENT=’‘1’’>");

writeoutput("</head><body>");

writeoutput("Your operator is " & session.operator & “<BR>”);

writeoutput(#session.conversation#);

writeoutput("</body></html>");

}

function getOperator(connection) {

roster = connection.getRoster();

//cfdump(roster);

group = roster.getGroup(“Operators”);

//cfdump(group);

count = group.getEntryCount();

//cfdump(count);

rand = RandRange(1,count);

//cfdump(rand);

it = group.getEntries();

//cfdump(it);

//for (i=1; i LTE rand; i=i+1) {

// entry = it.next();

//}

entry = it[rand];

//cfdump(entry.getName());

return entry.getName();

}

function getUserStatus(name, connection) {

roster = connection.getRoster();

// cfdump(roster);

contain = roster.contains(name & “@” & xmmpserver);

// cfdump(contain);

pres = roster.getPresence(name & “@” & xmmpserver);

// cfdump(variables);

if (Not IsDefined(“pres”)) {

group = roster.getGroup(“Friends”);

if (Not IsDefined(“group”)) {

roster.createGroup(“Friends”);

roster.reload();

}

groups = ArrayNew(1);

groups[1] = “Friends”;

roster.createEntry(name, name, groups);

roster.reload();

pres = roster.getPresence(name & “@” & xmmpserver);

}

if (IsDefined(“pres”)) return pres.getStatus();

return “”;

}

</cfscript>

<div id=“messages”>

</div>

<script>

function getXMLHttpComponentInstance() {

var xComp = null;

try {

xComp = new XMLHttpRequest();

} catch (e) {

try {

xComp = new ActiveXObject(“Microsoft.XMLHTTP”);

} catch (e) {

window.alert(“Your browser does not support this site yet, sorry”);

}

}

return xComp;

}

var messages_req;

function getMessages() {

messages_req = getXMLHttpComponentInstance();

messages_req.onreadystatechange = gotMessages;

    messages_req.open("GET", "http://bfd-sql3/cfjab/messages.cfm");

messages_req.setRequestHeader( “If-Modified-Since”, “Sat, 1 Jan 2000 00:00:00 GMT” );

messages_req.send("");

}

function gotMessages() {

//alert(messages_req.responseText);

if (messages_req != null && messages_req.readyState == 4) {

var messages = document.getElementById(“messages”);

//alert(messages_req.responseText);

messages.innerHTML += messages_req.responseText;

//alert(messages.innerHTML);

// alert(messages_req.responseText);

parent.chatwindow.scroll(9999999, 9999999);

setTimeout(“getMessages();”, 500);

}

}

getMessages();

</script>

Messages.cfm

<cfif IsDefined(“url.msg”)>

<cfscript>

// grab the connection and chat objects from the session

connection = session.connection;

chat = session.chat;

// send the message via the chat object

chat.sendMessage(url.msg);

// append the message to the conversation

newmessage = StructNew();

newmessage.text = "<strong><font color=’‘red’’>you</font></strong> : " & form.message;

//newmessage.seen = 1;

ArrayAppend(session.messages, newmessage);

session.conversation = session.conversation & "<br /><strong><font color=’‘red’’>you</font></strong> : " & url.msg;

</cfscript>

<cfabort>

</cfif>

<cfscript>

// get the connection & chat objects from the session

connection = session.connection;

chat = session.chat;

// retrieve the message using pollMessage() (which is nonblocking)

nextMessage = chat.pollMessage();

// if no message exists ‘‘nextMessage’’ will be undefined

if (IsDefined(“nextMessage”)) {

message = nextMessage.getBody();

if (IsDefined(“message”)) {

// message does exist, add it to the conversation

newmessage = StructNew();

newmessage.text = “<strong><font color=’‘blue’’>” & session.operator & "</font></strong> : " & message;

ArrayAppend(session.messages, newmessage);

session.conversation = session.conversation & “<br /><strong><font color=’‘blue’’>” & session.operator & "</font></strong> : " & message;

}

}

</cfscript>

<cfif IsDefined(“url.debug”)>

<cfdump var="#session.messages#">

</cfif>

<cfloop from=“1” to="#ArrayLen(session.messages)#" index=“i”>

<cfset message = session.messages[i]>

<cfif Not IsDefined(“message.seen”)>

<cfoutput>

#message.text#<br>

</cfoutput>

<cfif Not IsDefined(“url.debug”)>

<cfset message.seen = 1>

</cfif>

</cfif>

</cfloop>

Default.cfm

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>

<html>

<head>

<title></title>

</head>

<body>

<iframe src=“frame.cfm” name=“chatwindow” id=“chatwindow” width=“800” height=“500” marginwidth=“5” marginheight=“5”></iframe>

<cfscript>

// if we have a form post

if (isDefined(“url.action”)) {

if (url.action EQ “reset”) {

StructClear(Session);

}

}

if (IsDefined(“form.formPosted”) AND form.message NEQ “”) {

// grab the connection and chat objects from the session

connection = session.connection;

chat = session.chat;

// send the message via the chat object

chat.sendMessage(form.message);

// append the message to the conversation

newmessage = StructNew();

newmessage.text = "<strong><font color=’‘red’’>you</font></strong> : " & form.message;

newmessage.seen = 1;

ArrayAppend(session.messages, newmessage);

session.conversation = session.conversation & "<br /><strong><font color=’‘red’’>you</font></strong> : " & form.message;

}

</cfscript>

<cfoutput>

<form action="#cgi.script_name#" method=“post” onsubmit=“return sendMessage();”>

<input type=“text” id=“message” name=“message”>

<input type=“submit” name=“newmessage” value=“Send Message”>

<input type=“hidden” name=“formPosted” value=“1”>

</form>

<a href=“http://www.jivesoftware.org/community/post!reply.jspa#cgi.script_name#?action=re set”>Reset</a>

</cfoutput>

<script>

function getXMLHttpComponentInstance() {

var xComp = null;

try {

xComp = new XMLHttpRequest();

} catch (e) {

try {

xComp = new ActiveXObject(“Microsoft.XMLHTTP”);

} catch (e) {

window.alert(“Your browser does not support this site yet, sorry”);

}

}

return xComp;

}

function sendMessage() {

var textbox = document.getElementById(“message”);

var messages_req;

messages_req = getXMLHttpComponentInstance();

    messages_req.open("GET", "http://bfd-sql3/cfjab/messages.cfm?msg=" + text, true);       

messages_req.send("");

textbox.value = “”;

return false;

}

</script>

</body>

</html>

Probably best not to look at it there Lots of commenting out of lines and stuff as I tried to get it to work… and somehow its lost all indents

Message was edited by: andrewm1986

Still occurs on latest of everything

bump

I am experiencing the same issue as you are, however, I have this problem regardless of using a command line client, or the code i’'ve written in JSP.

I agree it seems to be the fact that the message is being sent with the element. It seems to not be accessible to the chat object using Chat.nextMessage()

Can we please have a response from the developers?

Andrew

I don’'t think it is the offline element. Spark does not respect the thread id of incoming messages, it creates its own so this may or may not have to do with the problem. Create a packetcollector which parses all incoming messages and see if you are at least receiving the message, and then we can narrow down as to why the particular packetcollector you are using is not working.

Thanks,

Alex

If it is not the offline element then please explain how sending a debug message with the offline element doesnt appear but sending one without it makes it appear?

I’'ve been having this same problem (using Java 1.5.x) and Smack 2.2.1. I can get chat to work between two Smack agents but not between Smack and Spark. The only difference I can see is that the Smack-to-Smack chat retains the original thread ID but in the Smack-to-Spark chat, Spark replaces the thread ID.

Is the PacketListener approach the way to go in the meantime?