Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

How to make a private chat look in another window

Avatar

Not applicable

hi

   iam new to flex

and now what my question is when i double click on the particular user present in the chat room

i should get chat open in new window

is this possible please help out in this issue

0 Replies

Avatar

Level 10

Hi,

Yes this is possible. I can give you a brief overview of how you can do it.

The UserList which is a List, you need to handle ItemDoubleClick event, and also I think you need to make doubleClickEnabled = true . Please check with the Asdocs for List class in flex for more details.

Regarding opening chat, when you double click, in the handler function, you need to add something like this to add SimpleChat

function doubleClickHandler(event:ListEvent):void

{

Var simpleChat:SimpleChat = new SimpleChat();

simpleChat.sharedID = "some id" ;

simpleChat.subscribe();

addChild(simpleChat);

simpleChat.width = "some width" ;

simpleChat.height = "some height" ;

}

SimpleChat extends a UIComponent, adding it is similar to adding an UIComponent , only thing is here you need to give it some id and call the method subscribe for the component to be synchronized.

Hope this helps.

Thanks

Hironmay Basu

Avatar

Not applicable

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

Employee

Hi Bharath, (Guess thats ur name,as it was in the code)

This should solve ur problem. The solution is simple, save the publisherId of the message u recieve in a private chat and send ur replies to that person.

protected function submitChat(str:String):void
            {              
             if(count==0)
             {
             clearChat();
             count=1;
             }
            var clickeduser:UserDescriptor = sess.userManager.userCollection[selindex] as UserDescriptor;
            var clickusername:String=clickeduser.displayName; 
            //private chat is between two people. So save the other person also in a protected var...
             cmd= new ChatMessageDescriptor();          
                if (_otherPrivateChatUser && clickeduser.userID == sess.userManager.myUserID) {
                    cmd.recipient=_otherPrivateChatUser;
                    cmd.recipientDisplayName=_otherUserName;
                } else {
                    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)
                  
                    {
                       //private chat is between two people. So save the other person also in a protected var...
                       if (p_evt.message.publisherID != sess.userManager.myUserID) {
                        _otherPrivateChatUser = p_evt.message.publisherID;
                        _otherUserName = p_evt.message.displayName;      
                       }
                    chat_mesg_area.text += "\r\n" +  p_evt.message.displayName + ": " + p_evt.message.msg;
                    }
                else
                    {
                  
                    chat_mesg_area.text = "";  
                    }
                  
            }

Thanks

Avatar

Not applicable

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