Presence always looking offline?, and AVAILABLE_TYPE constant

Hello,

I’m toying with a great reference script found at http://paazio.nanbudo.fi/tutorials/flash/xiff-chat-part-1 . It’s working great for the most part after making some tweaks for it to work in Flash CS3. One thing that didn’t work was the reference to Presence.AVAILABLE_TYPE. There is no AVAILABLE_TYPE specified in Presence.as, only UNAVAILABLE_TYPE.

I changed this:

presence = new Presence(null, userJID, Presence.AVAILABLE_TYPE, Presence.SHOW_CHAT, null, 1);

to this:

presence = new Presence(null, userJID, “available”, Presence.SHOW_CHAT, null, 1);

That fixed the error, but I’m still having issues. Whenever I send a message from Flash to my IM client, the sender appears to be offline. When I reply, I get the message asking if I want to send the message now or later because of the sender is offline. When I send a message though, it shows up in Flash just fine.

My output shows an error:

onConnectSuccess 3512
onXiffError: Unknown Error
onLogin 3741
onPresence 3811

Any thoughts on how to make the Flash sender appear online? Thanks much in advance.

Edit:

Here is a more complete output:

onConnectSuccess 3230
onXiffError: message:Unknown Error, condition: undefined-condition, type: modify, code: 500
onLogin 3324
onPresence [Event type=“presence” bubbles=false cancelable=false eventPhase=2]

This produces the same results:

presence = new Presence(null, connection.jid, null, Presence.SHOW_CHAT, null, 3);

From where is youre onXiffError arising?

Hello Juga,

I prepared a stripped down version for Flash CS3 (attached) with similar issues.

The 500 error is happening somewhere between connect and login. The output looks like this:

onConnectSuccess 214
onXiffError: message:Unknown Error, condition: undefined-condition, type: modify, code: 500
onLogin 315
onPresence [Event type=“presence” bubbles=false cancelable=false eventPhase=2]

Here’s the code:

import org.jivesoftware.xiff.core.*;
import org.jivesoftware.xiff.data.*;
import org.jivesoftware.xiff.events.*; var guestName:String = "Tester"; var connection:XMPPSocketConnection;
var presence:Presence;
var keepAlive:Timer;
var port:Number = 5222;
var resourceName:String = "flashPlayer";
var server:JID = new JID("SERVER ADDRESS HERE");
var userJID:JID = new JID("USERNAME@localhost");
var recipient:JID = new JID("CONTACT THIS USER@localhost");
var thePassword:String = "PASSWORD"; function addMessage(messageSender:String, theMessage:String):void {
     var date:Date = new Date();
     trace(messageSender + " " + date.getHours() + ":" + date.getMinutes() + ": " + theMessage);
} function sendMessage(theMessage:String,messageSender:String,showMessage:Boolean=true) {
     var msg:Message = new Message(recipient, null, theMessage, null, Message.CHAT_TYPE);
     if(connection.isLoggedIn()) {
          connection.send(msg);
          if(showMessage == true) {
               addMessage(messageSender, theMessage);
          }
     } else {
          trace('not logged in'); //expand on this soon
     }
} function initChat():void {
     var systemMessage:String = "One moment please...";
     addMessage("Chat System", systemMessage);
     connection = new XMPPSocketConnection();      connection.addEventListener(ConnectionSuccessEvent.CONNECT_SUCCESS, onConnectSuccess);
     connection.addEventListener(DisconnectionEvent.DISCONNECT, onDisconnect);
     connection.addEventListener(XIFFErrorEvent.XIFF_ERROR, onXiffError);
     connection.addEventListener(LoginEvent.LOGIN, onLogin);
     connection.addEventListener(MessageEvent.MESSAGE, onMessage);
     connection.addEventListener(PresenceEvent.PRESENCE, onPresence);
          connection.username = userJID.toString();
     connection.password = thePassword;
     connection.server = server.toString();
     connection.port = port;
     connection.resource = resourceName;
     connection.connect("standard");      keepAlive = new Timer(100000);
     keepAlive.addEventListener(TimerEvent.TIMER, onKeepAliveLoop);
     keepAlive.start();
          presence = new Presence(null, userJID, "available", Presence.SHOW_CHAT, null, 1);
} function onConnectSuccess(evt:ConnectionSuccessEvent):void {
     trace("onConnectSuccess " + getTimer());
} function onDisconnect(evt:DisconnectionEvent):void {
     trace("onDisconnect " + getTimer());
} function onXiffError(evt:XIFFErrorEvent):void {
     trace("onXiffError: message:" + evt.errorMessage + ", condition: " + evt.errorCondition + ", type: " + evt.errorType + ", code: " + evt.errorCode);
} function onLogin(evt:LoginEvent):void{
     trace("onLogin " + getTimer());
     connection.send(presence);
} function onMessage(evt:MessageEvent):void {
     trace("onMessage " + getTimer());
     trace(evt.data.time);
} function onPresence(evt:PresenceEvent):void {
     trace("onPresence " + evt.toString());
     var systemMessage = "Chat System says: " + guestName + " has connected and awaits your greeting. Please respond with a greeting ASAP for best results. :)";
     sendMessage(systemMessage, "", false);
} function onKeepAliveLoop(evt:TimerEvent):void {
     connection.sendKeepAlive();
} initChat();

I appoligize for not including this to begin with. Let me know if you have any thoughts. Much appriciated.

edit:

It looks like there is some odd spacing in the example posted above. It may be good to refrence the fla. Let me know if I can attach another file.
chatTemp2.fla (52224 Bytes)

Ah, read the instructions. That would help. This is strictly for Flex and not Flash. Well, this link will be helpful in moving forward:

Kinda cool I got messages sending though.

Thought I’d jump in here…

Despite what you might think, ‘strictly for flex and not flash’ does not exist.

Earlier this year I created my own Flash CS3 IM Client that uses XIFF as a base for XMPP connection.

It is fully functional with no errors… except some compatibility problems arising now with Flash Player 10.

Although it is possible, you need to modify the scripts that are provided in the XIFF AS3 Beta in order for it to function.

You have to create your own AVAILABLE_TYPE if I recall properly.