powered by Jive Software

Anonymous Logged In Users Always Appear Offline

Hello,

Using slightly rewritten code from this Flash (not Flex) example, I’m able to login anonymous users and send messages to non-anonymous users successfully: AWESOME.

Challenge: Those anonymous users always appear offline, even though there’s good two-way conversations taking place. Here’s my code below. You can test if you have the files from the link above, replacing the actionscript in there. May I have someone critique this and tell me what might be going wrong?

Thanks a ton in advance!

Chris

import flash.events.Event; import com.yourpalmark.chat.ChatManager;
import com.yourpalmark.chat.data.LoginCredentials;
import com.pixelbreaker.ui.osx.MacMouseWheel; import mx.collections.ArrayCollection;
import mx.events.CloseEvent;
import mx.events.FlexEvent;
import mx.events.ListEvent;
import mx.managers.PopUpManager;
import mx.events.ResizeEvent; import org.igniterealtime.xiff.conference.Room;
import org.igniterealtime.xiff.core.EscapedJID;
import org.igniterealtime.xiff.core.UnescapedJID;
import org.igniterealtime.xiff.data.Message;
import org.igniterealtime.xiff.data.Presence;
import org.igniterealtime.xiff.data.im.RosterGroup;
import org.igniterealtime.xiff.data.im.RosterItemVO;
import org.igniterealtime.xiff.events.DisconnectionEvent;
import org.igniterealtime.xiff.events.IncomingDataEvent;
import org.igniterealtime.xiff.events.InviteEvent;
import org.igniterealtime.xiff.events.LoginEvent;
import org.igniterealtime.xiff.events.MessageEvent;
import org.igniterealtime.xiff.events.OutgoingDataEvent;
import org.igniterealtime.xiff.events.PresenceEvent;
import org.igniterealtime.xiff.events.RegistrationSuccessEvent;
import org.igniterealtime.xiff.events.RosterEvent;
import org.igniterealtime.xiff.events.XIFFErrorEvent; //import mx.controls.ComboBox;
import org.igniterealtime.xiff.core.XMPPConnection;
import flash.net.XMLSocket; var chatManager:ChatManager;
var messageDict:Dictionary;
//var roomPopup:RoomPopup; //var errorDataProvider:ArrayCollection = new ArrayCollection();
var logDataProvider:ArrayCollection = new ArrayCollection();
var presenceDataProvider:Array =    [
                                                { label:"Online", data:Presence.SHOW_CHAT },
                                                { label:"Free To Chat", data:Presence.SHOW_CHAT },
                                                { label:"Away", data:Presence.SHOW_AWAY },
                                                { label:"Do Not Disturb", data:Presence.SHOW_DND },
                                                { label:"Extended Away", data:Presence.SHOW_XA }
                                            ]; var groupDataProvider:Array =    [
                                            { label:"Buddies", data:"Buddies" },
                                            { label:"Work", data:"Work" },
                                            { label:"Family", data:"Family" }
                                        ]; setupChatManager(); function setupChatManager():void
{
    chatManager = new ChatManager();
    chatManager.addEventListener( DisconnectionEvent.DISCONNECT, onDisconnect );
    chatManager.addEventListener( LoginEvent.LOGIN, onLogin );
    chatManager.addEventListener( XIFFErrorEvent.XIFF_ERROR, onXIFFError );
    chatManager.addEventListener( OutgoingDataEvent.OUTGOING_DATA, onOutgoingData );
    chatManager.addEventListener( IncomingDataEvent.INCOMING_DATA, onIncomingData );
    chatManager.addEventListener( PresenceEvent.PRESENCE, onPresence );
    chatManager.addEventListener( MessageEvent.MESSAGE, onMessage );
    chatManager.addEventListener( RosterEvent.USER_AVAILABLE, onUserAvailable );
    chatManager.addEventListener( RosterEvent.USER_UNAVAILABLE, onUserUnavailable );
} connectButton.addEventListener(MouseEvent.CLICK,LoginNow);
function LoginNow(e){
    connect();
} function connect():void
{     onServerInputChange();
    onServerPortInputChange();
    chatManager.connection.useAnonymousLogin = true;
    chatManager.connection.resource = "flashPlayer";     var credentials:LoginCredentials = new LoginCredentials();
    credentials.username = usernameInput.text;
    credentials.password = passwordInput.text;
    msgbox.text+=String("Connect? ");
    chatManager.connect(credentials); } function onDisconnect( event:DisconnectionEvent ):void
{
    msgbox.text+=String("User disconnected");
} function onLogin( event:LoginEvent ):void
{
    msgbox.text+="Success:"+String(chatManager.currentUserJID);
    setInterval(KeepActive,1000*60);     var presence:Presence = new Presence(null, chatManager.connection.jid.escaped, null, "chat", "Nice day for a talk", 1);
    chatManager.connection.send(presence); }
function KeepActive(){
    //msgbox.text+="$"
    chatManager.connection.sendKeepAlive();
} function onXIFFError( event:XIFFErrorEvent ):void
{
    msgbox.text+="Error:"+String(event.errorMessage);
} function onOutgoingData( event:OutgoingDataEvent ):void
{
    //msgbox.text+="onOutgoingData:"+event.data.toString();
    //logDataProvider.addItem( ">>outgoing: " + event.data.toString() );
} function onIncomingData( event:IncomingDataEvent ):void
{
    logDataProvider.addItem( ">>incoming: " + event.data.toString() );
} //chatManager.connection.sendKeepAlive(); function onPresence( event:PresenceEvent ):void
{     var presence:Presence = event.data[ 0 ] as Presence;
    var presenceType:String;     switch( presence.type )
    {
        case Presence.SHOW_CHAT :
        case Presence.SHOW_AWAY :
        case Presence.SHOW_DND :
        case Presence.SHOW_XA :
            presenceType = "Presence.AVAILABLE_TYPE";
            break;
        case Presence.UNAVAILABLE_TYPE :
            presenceType = "Presence.UNAVAILABLE_TYPE";
            break;
        case Presence.UNSUBSCRIBE_TYPE :
            presenceType = "Presence.UNSUBSCRIBE_TYPE";
            break;
        case Presence.PROBE_TYPE :
            presenceType = "Presence.PROBE_TYPE";
            break;
        default :
            break;
    }     //msgbox.text+="presenceType: "+presence.show;
} function onMessage( event:MessageEvent ):void
{
    var message:Message = event.data as Message;
    msgbox.text+="Message:"+" ["+String(event.data.from.bareJID)+ "] "+String(event.data.body);
} function onUserAvailable( event:RosterEvent ):void
{
    msgbox.text+="User Available:"+event.jid;
    //logDataProvider.addItem( "RosterEvent.USER_AVAILABLE: " + event.jid );
    //callLater( updateLogScrollPosition );
} function onUserUnavailable( event:RosterEvent ):void
{
    msgbox.text+="User Unavailable:"+event.jid;
    //logDataProvider.addItem( "RosterEvent.USER_UNAVAILABLE: " + event.jid );
    //callLater( updateLogScrollPosition );
} function onServerInputChange():void
{
    ChatManager.serverName = serverInput.text;
} function onServerPortInputChange():void
{
    ChatManager.serverPort = parseInt(serverPortInput.text);
}   function onPresenceStateChange( event:ListEvent ):void
{ }
//////////////////////////////////
sendButton.addEventListener(MouseEvent.CLICK,sendMessageNow) function sendMessageNow(e){
    sendMessage(toChat.text,msgTxt.text);
} function sendMessage(toId,str){
        //fromId=new EscapedJID(fromId);
        toId=new EscapedJID(toId);
        var message:Message = new Message( toId, "Tester", null, null, Message.CHAT_TYPE, null );
        message.from = chatManager.currentUserJID;
        message.body = str;
        message.state = "active"; //org.igniterealtime.xiff.data.ChatState: active, composing, paused, inactive, gone          chatManager.connection.send(message);
}

Chris,

when you debug the client by looking at the stanzas sent to the server, does the initial presence stanza get sent?

daryl

Hello daryl,

Thanks for the response.

Hmm. Below is what the ingoing/outgoing data looks like when signing in and sending a single message. In there, I did see a presence update, but it was not very initial looking:

===

outgoing: chatNice day for a talk1

===

Full:

outgoing: <?xml version="1.0"?><stream:stream to=“my.server.com” xmlns=“jabber:client” xmlns:stream=“http://etherx.jabber.org/streams” version=“1.0”>

incoming: <?xml version='1.0' encoding='UTF-8'?><stream:stream xml:lang=“en” version=“1.0” id=“ddad4984” from=“appsvr” xmlns=“jabber:client” xmlns:stream=“http://etherx.jabber.org/streams” />

incoming: stream:featuresPLAINANONYMOUSzlib</stream:features>

outgoing:

incoming:

outgoing: <?xml version="1.0"?><stream:stream to=“my.server.com” xmlns=“jabber:client” xmlns:stream=“http://etherx.jabber.org/streams” version=“1.0”>

incoming: <?xml version='1.0' encoding='UTF-8'?><stream:stream xml:lang=“en” version=“1.0” id=“ddad4984” from=“appsvr” xmlns=“jabber:client” xmlns:stream=“http://etherx.jabber.org/streams”>stream:featureszlib</stream:features></stream:stream>

outgoing: flashPlayer

incoming: ddad4984@appsvr/ddad4984</b ind>

outgoing:

incoming:

outgoing: chatNice day for a talk1

outgoing:

outgoing: Online5

incoming:

outgoing: testing…