Expand my Community achievements bar.

Sane private stream/chat sample app

Avatar

Former Community Member

Hello again,

I've managed to get LCCS running and created some demo apps for myself to play. I've come to a bit of a stop on a private stream application. After reading some documentation and browsing the sample applications on the LCCS SDK Navigator, I've managed to come up with this ( stripped out most of the layout hbox/vbox ):

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:rtc="AfcsNameSpace" applicationComplete="init()">
   
    <mx:Script>
        <![CDATA[
            import com.adobe.rtc.events.SessionEvent;
            import com.adobe.rtc.sharedManagers.*;
            import com.adobe.rtc.sharedModel.descriptors.ChatMessageDescriptor;
            import com.adobe.rtc.sharedModel.SimpleChatModel;
            import com.adobe.rtc.events.ChatEvent;
           
            [Bindable] public var chatModel:SimpleChatModel;
            [Bindable] public var ids:Array = new Array();
            [Bindable] public var myId:String;
           
            protected function init():void {
                buildModel();
            }
           
            protected function buildModel():void {
                chatModel = new SimpleChatModel();
                chatModel.sharedID = "myChat_SimpleChatModel";
               
                chatModel.subscribe();
                chatModel.addEventListener(ChatEvent.HISTORY_CHANGE, onChatMsg);
            }
           
            protected function onChatMsg(p_evt:ChatEvent):void {
                if(p_evt.message != null && p_evt.message.msg != null && p_evt.message.displayName != null)
                    conversationText.text += "\r\n" +  p_evt.message.displayName + ": " + p_evt.message.msg;
                else
                    conversationText.text = "";
            }
           
            public function connect_peer():void {
                webCamPub.subscribe();
                webCamPub.publish();
               
                webCamSub.subscribe();
               
                audioPub.codec = SoundCodec.SPEEX;
                audioPub.subscribe();
               
                audioSub.subscribe();
                audioSub.setLocalVolume(1);
                audioPub.publish();
            }
           
            public function sendMessage():void {
                var cmd:ChatMessageDescriptor = new ChatMessageDescriptor();
                cmd.recipient = ids[0];
                cmd.msg = textSend.text;
                   
                chatModel.sendMessage( cmd );
            }
           
            protected function connect():void {
                var newIds:Array = new Array( publisherId.text );
                ids = null;
                ids = newIds;
               
                connect_peer();
               
            }

            protected function connectSessionChange(event:com.adobe.rtc.events.SessionEvent):void {
                var user:UserManager = connectSession.userManager;
               
                myId = user.myUserID;
            }
        ]]>
    </mx:Script>
   
    <rtc:ConnectSessionContainer id="connectSession" roomURL="roomUrl">
        <rtc:authenticator><rtc:AdobeHSAuthenticator userName="Guest"></rtc:AdobeHSAuthenticator></rtc:authenticator>
       
        <rtc:WebcamPublisher id="webCamPub" width="10" height="5"/>
        <rtc:WebcamSubscriber publisherIDs="{ids}" id="webCamSub" webcamPublisher="{webCamPub}" width="320" height="240"/>
         <rtc:AudioPublisher id="audioPub"/>

        <rtc:AudioSubscriber id="audioSub"/>


        <mx:TextInput id="myid" width="100%" height="100" text="{myId}"/>
       
        <mx:TextInput id="publisherId" />
        <mx:Button click="connect()"/>

        <mx:TextArea width="100%" height="80%" id="conversationText" />

        <mx:TextInput width="80%" height="15%" id="textSend" />

        <mx:Button width="15%" height="15%" label="Send" click="sendMessage()" />
    </rtc:ConnectSessionContainer>
</mx:Application>

With this, It should enable 2 users to have a private chat/stream, without another entering.

Assuming the code above is sane enough, I have a few questions:


1. Are there any events tied to connecting/disconnecting of the peer user?

2. How can I find out when the user connected to LCCS service? (is the connectSessionChange function enough?)

3. Is it safe to assume that UserManager.myUserId is unique and is generated each time the user connects to LCCS service?

2 Replies

Avatar

Former Community Member

Hi ,

To answer your questions:

a) When any user leaves the room, you get an UserEvent.USER_REMOVE from UserManager. This will have the userid of the user left.

b) You can listen to SessionEvent.SYNCHRONIZATION_CHANGE in ConnectSession check for connectSession.isSynchronized value for true/false when an user is connected to or disconnected from LCCS room.

c) The UserIds are unique as you get in.

Hope this helps

Thanks

Hironmay Basu

Avatar

Former Community Member

Thank you for the answers, they sure do help