Expand my Community achievements bar.

SOLVED

How to get username present in chat

Avatar

Former Community Member

hi

     my problem is

   i am trying to get usernames  which will be appearing in listbox in chat function but iam unable to get it so can any one help me how to get them

iam placing that code here

the code which is in red where i got stuck iam unable to get users name present in that list box so can any one hlep me

plzzzz it will be very usefull to as iam new to flex and the code is ruuning on (afcs) flex 3

<?xml version="1.0" encoding="utf-8"?>
<mx:Application layout="absolute"
    xmlns:mx="http://www.adobe.com/2006/mxml"
    applicationComplete="init()"
    xmlns:rtc="AfcsNameSpace">
   
    <mx:Script>
        <![CDATA[
            import com.adobe.rtc.sharedManagers.UserManager;
            import com.adobe.rtc.sharedManagers.descriptors.UserDescriptor;
            import mx.controls.listClasses.IListItemRenderer;
            import mx.controls.listClasses.ListBaseSelectionData;
            import mx.collections.IList;
            import mx.events.ItemClickEvent;
            import mx.controls.Alert;
            import com.adobe.rtc.events.AuthenticationEvent;
            import com.adobe.rtc.events.ConnectSessionEvent;
            import com.adobe.rtc.events.SessionEvent;
            import mx.core.IFlexDisplayObject;
            import mx.managers.PopUpManager;
            import flash.net.*;
            import mx.collections.ArrayCollection;
           
            private const applicationTitle:String = "AFCS Sample Application";
              [Bindable]
        
           public var cmd:UserManager=new UserManager;
           public var bharath:Array=new Array;
            private function init():void
            {
                sess.addEventListener(SessionEvent.ERROR, onEventNotification);
                sess.addEventListener(SessionEvent.SYNCHRONIZATION_CHANGE, onEventNotification);
                auth.addEventListener(AuthenticationEvent.AUTHENTICATION_FAILURE, onEventNotification);
                auth.addEventListener(AuthenticationEvent.AUTHENTICATION_SUCCESS, onEventNotification);
               
                popup(loginWindow);
            }
           
            private function popup(window:IFlexDisplayObject):void
            {
                PopUpManager.addPopUp(window, this, true);
                PopUpManager.centerPopUp(window);
                window.visible = true;
            }

            /**
             * Process AFCS Events
             */
            private function onEventNotification(p_event:Event):void
            {
                if (p_event.type == SessionEvent.SYNCHRONIZATION_CHANGE) {
                    if (sess.isSynchronized) {
                        //
                        // isSyncronized==true : we are connected to the room
                        //
                        panel.title = "Connected to room " + sess.roomURL;
                        PopUpManager.removePopUp(loginWindow);
                    } else {
                        //
                        // isSyncronized==false : we are disconnected from the room
                        //
                        panel.title = applicationTitle;
                        sess.roomURL = null;
                        notificationMessage.text = "";
                        popup(loginWindow);
                    }
                }
               
                else if (p_event.type == AuthenticationEvent.AUTHENTICATION_SUCCESS) {
                    //
                    // Authentication succeeded
                    //
                    notificationMessage.text = "Authentication Succeeded";
                }
               
                else if (p_event.type == AuthenticationEvent.AUTHENTICATION_FAILURE) {
                    //
                    // Authentication failed : bad password or invalid username
                    //
                    notificationMessage.text = "Authentication Failed";
                }
               
                else if (p_event.type == SessionEvent.ERROR) {
                    //
                    // Generic session error, but this can happen if you mispell the account/room names
                    // (sError.error.name == "INVALID_INSTANCE" and sError.error.message == "Invalid Instance")
                    //
                    var sError:SessionEvent = p_event as SessionEvent;
                    notificationMessage.text = sError.error.message;
                }
               
                else
                    notificationMessage.text = "Got event " + p_event;
            }
           
            private function login():void
            {
                notificationMessage.text = "";
                auth.userName = username.text;
                auth.password = passwordBox.visible ? password.text : null; // password==null : the user is a guest
                sess.roomURL = roomURL.text;       
                sess.login();
            }
           
            public function userclick(bharath):void
            {
                Alert.show(bharath)
            }
        ]]>
    </mx:Script>       
    <rtc:AdobeHSAuthenticator id="auth"/>       
    <rtc:RoomSettings id="settings" autoPromote="true"/>

    <mx:Panel id="panel" title="{applicationTitle}" width="100%" height="100%" paddingLeft="5" paddingTop="5" paddingRight="5" paddingBottom="5">
   
        <!--
         | Login Dialog Box
         -->
        <mx:TitleWindow id="loginWindow" title="Connect to Room" visible="false">
            <mx:VBox>
                <mx:HBox>
                    <mx:Label text="Room URL:" width="70"/>
                    <mx:TextInput id="roomURL" width="295" tabIndex="1">
                        <mx:text>http://connect.acrobat.com/exampleURL/exampleroom</mx:text>
                    </mx:TextInput>
                </mx:HBox>
                <mx:HBox>
                    <mx:Label text="Username:" width="70"/>
                    <mx:TextInput id="username" tabIndex="2">
                        <mx:text>guest</mx:text>
                    </mx:TextInput>           
                    <mx:Button label="Login" click="login()" width="126" tabIndex="4"/>
                </mx:HBox>
                <mx:HBox>
                    <mx:HBox id="passwordBox">
                    <mx:Label text="Password:" width="70"/>
                    <mx:TextInput id="password" displayAsPassword="true" tabIndex="3"/>
                    </mx:HBox>
                    <mx:RadioButton label="User" selected="true" click="passwordBox.visible = true"/>
                    <mx:RadioButton label="Guest" click="passwordBox.visible = false"/>
                </mx:HBox>
                <mx:Text id="notificationMessage" text=""/>
            </mx:VBox>
        </mx:TitleWindow>

        <!--
         | AFCS application UI wrapped in ConnectSession
         -->       
        <rtc:ConnectSessionContainer
            id="sess"
            authenticator="{auth}"
            initialRoomSettings="{settings}"
            autoLogin="false" width="100%" height="100%" >       
            <mx:HBox width="100%" height="100%" horizontalGap="0">
                <mx:VBox>
                    <mx:TabBar dataProvider="viewStack" direction="vertical" width="100" verticalGap="0"/>
                    <!--mx:Button label="Disconnect" click="sess.close()"/-->
                </mx:VBox>

                <mx:ViewStack id="viewStack" width="100%" height="100%" borderSides="left top right bottom" borderStyle="solid" borderThickness="2">
                    <!--
                     | Chat pod and roster
                     -->
                    <mx:HBox label="Chat" width="100%" height="100%">
                        <rtc:SimpleChat width="40%" height="100%"/>
                        <rtc:WebCamera left="0" right="0" top="0" bottom="0" width="40%" height="100%"/>
                        <mx:List alternatingItemColors="[#DFDFDF,#EEEEEE]" dataProvider="{sess.userManager.userCollection}" width="10%" height="100%" labelField="displayName" id="abc"  itemClick="userclick(sess.userManager.userCollection.list.toArray())"/>

                      
                     
                    </mx:HBox>
                    <!--
                     | Whiteboard pod
                     -->
                   
                   
                        <!-- for some strange reason the shapesToolBar starts outside the WhiteBoard canvas
                            so when the whiteBoard is created I move shapesToolBar back to where it should be
                        <rtc:SharedWhiteBoard id="wb" left="0" right="0" top="0" bottom="0"
                            creationComplete="wb.shapesToolBar.move(0,0)"/>
                    </mx:Canvas>-->
   
                    <!--
                     | Fileshare pod
                     -->
                    <mx:Canvas label="FileShare" width="100%" height="100%">
                        <rtc:FileShare left="0" right="0" top="0" bottom="0"/>
                    </mx:Canvas>
                </mx:ViewStack>
            </mx:HBox>
        </rtc:ConnectSessionContainer>
    </mx:Panel>
</mx:Application>

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi,

You can get the userDesciptor of the user you clicked from event.currentTarget since you gave the userCollection as the dataProvider to the list.

Once you have userDescriptor and hence the userID of the recipient, you send a message item. You can use SharedProperty to send a message to the user.

Since it’s a private message, you can also use recipientID to only send message to that user. User should listen to the itemReceive and on reciving the message, should create a chat in a way I specified in a previous message.

Please go into Asdocs and read more about publishing messages , sharedproperty etc and also see examples for getting this to work.

Thanks

Hironmay Basu

View solution in original post

8 Replies

Avatar

Former Community Member

Hi,

I copied and ran your exact code and I could see the name clearly on the List. There was no problem when I ran it. Can you run it again. Can you please run it once more?You code looks and runs perfect for me.

I just want to make one extra note in case you use in future customFields of userCollection, you need to do it like this.

Attaching an example of DataGrid using customField

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns:rtc="AfcsNameSpace" >

<mx:Script>

<![CDATA[

import com.adobe.rtc.sharedManagers.UserManager;

private var _userManager:UserManager ;

public function onCreationComplete():void

{

_userManager = cSession.userManager ;

if (!_userManager.isCustomFieldDefined('score')) {

_userManager.registerCustomUserField('score');

}

userManager.setCustomUserField(userManager.myUserID,'score','7');

}

private function scoreLabelFunction(item:Object,column:DataGridColumn):String

{

return item.customFields['score'] ;

}

]]>

</mx:Script>

<rtc:ConnectSessionContainer id="cSession" roomURL="Your Room Url">

<rtc:authenticator>

<rtc:AdobeHSAuthenticator userName="Your UserName" password="Your Password" />

</rtc:authenticator>

<mx:DataGrid id="datag" dataProvider="{cSession.userManager.userCollection}" creationComplete="onCreationComplete()" >

<mx:columns>

<mx:DataGridColumn id="c1" headerText="Name" dataField="displayName" />

<mx:DataGridColumn id="c2" headerText="Score" dataField="customFields['score']" labelFunction="scoreLabelFunction" />

</mx:columns>

</mx:DataGrid>

</rtc:ConnectSessionContainer>

</mx:Application

So, for defined fields you just do labelField="fieldname" like you are doing for displayName and for customFields , you do labelField="customFields['fieldName']" provided the field is defined.

Thanks

Hironmay Basu

Avatar

Former Community Member

thanks for replying its working

and now wt  i want is i want to open the chat in a new window when i click on a particular user

and the conversion should be done privately means only they both should see that window is this possible

plz reply me

Avatar

Former Community Member

I replied to you regarding creation of a standalone chat in other message. What do you mean by they both should see and conversion being done privately. If you want a chat window to be popped up in every user, best is send some message on doubleClick to everyone ( you can do this by using SharedProperty) and everyone after receiving the message creates their chat window on the client.

Thanks

Hironmay Basu

Avatar

Former Community Member

hi

My requirement in detail is as follows:

when i click on another user, i need a separate chat window to be popped up for me and the user i clicked on,

so that from then onwards a chat exclusive to us (me and the user i clicked on) can be carried out in the popped up windows on both our screens.is this possible?

please reply.

          Thanks in advance.

Avatar

Correct answer by
Former Community Member

Hi,

You can get the userDesciptor of the user you clicked from event.currentTarget since you gave the userCollection as the dataProvider to the list.

Once you have userDescriptor and hence the userID of the recipient, you send a message item. You can use SharedProperty to send a message to the user.

Since it’s a private message, you can also use recipientID to only send message to that user. User should listen to the itemReceive and on reciving the message, should create a chat in a way I specified in a previous message.

Please go into Asdocs and read more about publishing messages , sharedproperty etc and also see examples for getting this to work.

Thanks

Hironmay Basu

Avatar

Former Community Member

hi

   thanks for urs replys its helping a lot

and now i wnt some information from u abt private chat

see wt my doubt is iam getting user name and uid when i click on the user in the userlist with that iam creating an instance to the class "ChatMessageDescriptor" and with that iam sending msgs to the user clicked by the property recipient

and iam initiating that private chat in seperate label privatechat space and now wt the problem is when i click on the username

for example iam the user A and i clicked on user B the window gets open for userA and user A can send msgs to user B directly

but where as in place of User B the window doesnot get open,  only when he clicks on User A  he is able to send msgs to User A and he can chat w User A directly from there on words

so wt i want is how to intiate him that chat is open with User A  so click him in the userlist  or directly open him a window as soon as User A clicks

User B is this possible plz refer my code u will get clearly understood the problem

<?xml version="1.0" encoding="utf-8"?>
<mx:Application layout="absolute"
    xmlns:mx="http://www.adobe.com/2006/mxml"
    applicationComplete="init()"
    xmlns:rtc="AfcsNameSpace">
   
    <mx:Script>
        <![CDATA[
            import com.adobe.rtc.pods.simpleChatClasses.ChatMessageDescriptor;
            import com.adobe.coreUI.controls.WhiteBoard;
            import com.adobe.rtc.sharedModel.SharedCollection;
            import com.adobe.rtc.sharedManagers.UserManager;
            import com.adobe.rtc.sharedManagers.descriptors.UserDescriptor;
            import mx.controls.listClasses.IListItemRenderer;
            import mx.controls.listClasses.ListBaseSelectionData;
            import mx.collections.IList;
            import mx.events.ItemClickEvent;
            import mx.controls.Alert;
            import com.adobe.rtc.events.AuthenticationEvent;
            import com.adobe.rtc.events.ConnectSessionEvent;
            import com.adobe.rtc.events.SessionEvent;
            import mx.core.IFlexDisplayObject;
            import mx.managers.PopUpManager;
            import flash.net.*;
            import mx.collections.ArrayCollection;
            import com.adobe.rtc.pods.simpleChatClasses.SimpleChatModel;
            import com.adobe.rtc.events.ChatEvent;
           
            private const applicationTitle:String = "AFCS Sample Application";
              [Bindable]
       public var chatModel:SimpleChatModel;
       public var clickeduser:UserDescriptor = new UserDescriptor;
         public var userwnt:String=new String;
          public var clickusername:String=new String;
           public var selindex:int;
           public var count:int;
            
            private function init():void
            {
                sess.addEventListener(SessionEvent.ERROR, onEventNotification);
                sess.addEventListener(SessionEvent.SYNCHRONIZATION_CHANGE, onEventNotification);
                auth.addEventListener(AuthenticationEvent.AUTHENTICATION_FAILURE, onEventNotification);
                auth.addEventListener(AuthenticationEvent.AUTHENTICATION_SUCCESS, onEventNotification);
               
                popup(loginWindow);
            }
           
            private function popup(window:IFlexDisplayObject):void
            {
                PopUpManager.addPopUp(window, this, true);
                PopUpManager.centerPopUp(window);
                window.visible = true;
            }

            /**
             * Process AFCS Events
             */
            private function onEventNotification(p_event:Event):void
            {
                if (p_event.type == SessionEvent.SYNCHRONIZATION_CHANGE) {
                    if (sess.isSynchronized) {
                        //
                        // isSyncronized==true : we are connected to the room
                        //
                        panel.title = "Connected to room " + sess.roomURL;
                        PopUpManager.removePopUp(loginWindow);
                    } else {
                        //
                        // isSyncronized==false : we are disconnected from the room
                        //
                        panel.title = applicationTitle;
                        sess.roomURL = null;
                        notificationMessage.text = "";
                        popup(loginWindow);
                    }
                }
               
                else if (p_event.type == AuthenticationEvent.AUTHENTICATION_SUCCESS) {
                    //
                    // Authentication succeeded
                    //
                    notificationMessage.text = "Authentication Succeeded";
                }
               
                else if (p_event.type == AuthenticationEvent.AUTHENTICATION_FAILURE) {
                    //
                    // Authentication failed : bad password or invalid username
                    //
                    notificationMessage.text = "Authentication Failed";
                }
               
                else if (p_event.type == SessionEvent.ERROR) {
                    //
                    // Generic session error, but this can happen if you mispell the account/room names
                    // (sError.error.name == "INVALID_INSTANCE" and sError.error.message == "Invalid Instance")
                    //
                    var sError:SessionEvent = p_event as SessionEvent;
                    notificationMessage.text = sError.error.message;
                }
               
                else
                    notificationMessage.text = "Got event " + p_event;
            }
         
            private function login():void
            {
                notificationMessage.text = "";
                auth.userName = username.text;
                auth.password = passwordBox.visible ? password.text : null; // password==null : the user is a guest
                 userwnt=username.text;
                sess.roomURL = roomURL.text;       
                sess.login();
            }
            protected function buildModel():void
            {
                // Create the model: just calling the constructor won't create the collection node or pass the messages.
                // Call subscribe and give it a shared ID while creating the model.
                // The shared ID becomes the name of the collection node.
                  if(clickusername==userwnt)
                    {
                     Alert.show(clickusername);
                     viewStack.selectedChild=white;
                    }
                chatModel = new SimpleChatModel();
                chatModel.sharedID = "myChat_SimpleChatModel";                               
                chatModel.subscribe();                       
                chatModel.addEventListener(ChatEvent.HISTORY_CHANGE, onChatMsg);
                this.addEventListener(KeyboardEvent.KEY_UP, onKeyStroke);
               
            }
           
             public var cmd:ChatMessageDescriptor = new ChatMessageDescriptor();
            public function userclick(bharath):void
            {
                count=0;     
                selindex=bharath;
                clickeduser= sess.userManager.userCollection[bharath] as UserDescriptor;
                var orignaluser:UserDescriptor = sess.userManager.userCollection[0] as UserDescriptor;
                var username=orignaluser.displayName;
                clickusername=clickeduser.displayName;  
                cmd= new ChatMessageDescriptor();           
                cmd.recipient=clickeduser.userID;
                cmd.recipientDisplayName=clickusername;
                cmd.msg="hi";               
                viewStack.selectedChild=white;
                  buildModel();                
                chatModel.sendMessage(cmd);                                  
              
            }
                protected function clearChat():void
            {
                chat_mesg_area.text = "";
                chatModel.clear();
            }
            protected function submitChat(str:String):void
            {               
             if(count==0)
             {
             clearChat();
             count=1;
             }
            var clickeduser:UserDescriptor = sess.userManager.userCollection[selindex] as UserDescriptor;
            var clickusername=clickeduser.displayName;  
             cmd= new ChatMessageDescriptor();           
                cmd.recipient=clickeduser.userID;
                cmd.recipientDisplayName=clickusername;
                cmd.msg=chat_mesg_input.text;                 
                chatModel.sendMessage(cmd);
                chat_mesg_input.text = "";               
            }
            protected function onChatMsg(p_evt:ChatEvent):void
            {
                if(p_evt.message != null && p_evt.message.msg != null && p_evt.message.displayName != null)
                   
                    {
                   
                    chat_mesg_area.text += "\r\n" +  p_evt.message.displayName + ": " + p_evt.message.msg;
                    }
                else
                    {
                   
                    chat_mesg_area.text = "";   
                    }
                   
            }
           
            protected function onKeyStroke(p_evt:KeyboardEvent):void
            {
                if(p_evt.keyCode == Keyboard.ENTER) {
                    submitChat(chat_mesg_input.text);
                }
            }
        ]]>
    </mx:Script>       
    <rtc:AdobeHSAuthenticator id="auth"/>       
    <rtc:RoomSettings id="settings" autoPromote="true"/>

    <mx:Panel id="panel" title="{applicationTitle}" width="100%" height="100%" paddingLeft="5" paddingTop="5" paddingRight="5" paddingBottom="5">
   
        <!--
         | Login Dialog Box
         -->
        <mx:TitleWindow id="loginWindow" title="Connect to Room" visible="false">
            <mx:VBox>
                <mx:HBox>
                    <mx:Label text="Room URL:" width="70"/>
                    <mx:TextInput id="roomURL" width="295" tabIndex="1">
                        <mx:text>http://connect.acrobat.com/exampleURL/exampleroom</mx:text>
                    </mx:TextInput>
                </mx:HBox>
                <mx:HBox>
                    <mx:Label text="Username:" width="70"/>
                    <mx:TextInput id="username" tabIndex="2">
                        <mx:text>guest</mx:text>
                    </mx:TextInput>           
                    <mx:Button label="Login" click="login()" width="126" tabIndex="4"/>
                </mx:HBox>
                <mx:HBox>
                    <mx:HBox id="passwordBox">
                    <mx:Label text="Password:" width="70"/>
                    <mx:TextInput id="password" displayAsPassword="true" tabIndex="3"/>
                    </mx:HBox>
                    <mx:RadioButton label="User" selected="true" click="passwordBox.visible = true"/>
                    <mx:RadioButton label="Guest" click="passwordBox.visible = false"/>
                </mx:HBox>
                <mx:Text id="notificationMessage" text=""/>
            </mx:VBox>
        </mx:TitleWindow>

        <!--
         | AFCS application UI wrapped in ConnectSession
         -->       
        <rtc:ConnectSessionContainer
            id="sess"
            authenticator="{auth}"
            initialRoomSettings="{settings}"
            autoLogin="false" width="100%" height="100%" >       
            <mx:HBox width="100%" height="100%" horizontalGap="0">
                <mx:VBox>
                    <mx:TabBar dataProvider="viewStack" direction="vertical" width="100" verticalGap="0"/>
                    <!--mx:Button label="Disconnect" click="sess.close()"/-->
                </mx:VBox>

                <mx:ViewStack id="viewStack" width="100%" height="100%" borderSides="left top right bottom" borderStyle="solid" borderThickness="2">
                    <!--
                     | Chat pod and roster
                     -->
                    <mx:HBox label="Chat" width="100%" height="100%">
                        <rtc:SimpleChat width="40%" height="100%"/>
                        <rtc:WebCamera left="0" right="0" top="0" bottom="0" width="40%" height="100%"/>
                        <mx:List alternatingItemColors="[#DFDFDF,#EEEEEE]" dataProvider="{sess.userManager.userCollection}" width="10%" height="100%" labelField="displayName" id="abc" click="userclick(abc.selectedIndex)"/>
                      
                     
                    </mx:HBox>
                    <mx:Canvas id="white" label="privatechat" width="100%" height="100%" creationComplete="buildModel()">
                     <mx:VBox id="chatBox">
                <rtc:WebCamera id="webcam" width="400" height="223"/>
                <mx:TextArea width="398" height="140" id="chat_mesg_area"/>
                <mx:HBox>
                </mx:HBox>                               
            </mx:VBox>
            <mx:TextInput width="400" id="chat_mesg_input" y="370"/>
            <mx:Button label="Submit Chat" click="submitChat(chat_mesg_input.text)" y="398"/>
            </mx:Canvas>
   
                    <!--
                     | Fileshare pod
                     -->
                    <mx:Canvas label="FileShare" width="100%" height="100%">
                        <rtc:FileShare left="0" right="0" top="0" bottom="0"/>
                    </mx:Canvas>
                </mx:ViewStack>
            </mx:HBox>
        </rtc:ConnectSessionContainer>
    </mx:Panel>
</mx:Application>

Avatar

Former Community Member

hi

   thanks for ur replies once again

i have checked ur code but its not working its working same as my code see wt i want is u have obeserved in my code there is a label called private chat

when i click on the user in the userlist  i used to get open the chat  for both of them on both sides and its working iam able to send messages to him but on the clicked user side he doesnot know that i sent him a private chat untill he clicks on the label  so can u plz tell him how to notify him that iam on private chat w him when i clicked on him i used to send msg only for him

i have seen there is class message Item with that we can send private msgs but wt happens is iam not getting the userid of the clicked user on the list

its showing like  "test0.pannel.sess" so how could i get the user id please tell me if i get that recipent id i hope i am able to get there

thank u

Avatar

Former Community Member

Hi usercollection,

A word of advice - punctuation and actually spelling out words makes requests easier to read.

What you probably want to do is have everyone subscribing to a simpleChatModel before anyone clicks on the user list. Clicking on the user list would bring up a chat UI that talks to the simpleChatModel. If the receiving user gets a message from the simpleChatModel, pop up the chat UI if it's not already up.

hope that helps

nigel

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----