Expand my Community achievements bar.

SOLVED

Connect vs Disconnect with UserEvent.SYNCHRONIZATION_CHANGE

Avatar

Former Community Member

I'm using the UserEvent.SYNCHRONIZATION_CHANGE event to determine when the current user connects or disconnects from a room. Since SYNCHRONIZATION_CHANGE fires for both loging in and logging out, what is the best way to distinguish between the connecting and disconnecting?http://livedocs.adobe.com/labs/acrobatcom/com/adobe/rtc/events/UserEvent.html#SYNCHRONIZATION_CHANGE

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi,

You can look for isSynchronized property in your ConnectSession/CollectionNode as true or false for login or logout respectively.

You can see plenty of examples in sharedModel/SharedManager classes where we use this property in the handler for SYNCHRONIZATION_CHANGE event

Thanks

Hironmay Basu

View solution in original post

5 Replies

Avatar

Correct answer by
Former Community Member

Hi,

You can look for isSynchronized property in your ConnectSession/CollectionNode as true or false for login or logout respectively.

You can see plenty of examples in sharedModel/SharedManager classes where we use this property in the handler for SYNCHRONIZATION_CHANGE event

Thanks

Hironmay Basu

Avatar

Former Community Member

Thanks for your response. I have two quesitons.

1) I wasn't able to find the example you mentioned (sharedModel/SharedManager). I found sampleApps/SharedModel/*, but didn't see SharedManager classes in there. Where can I find these classes?

2) I misunderstood you when you said "You can look for isSynchronized property in your  ConnectSession/CollectionNode". I started watching cSession.isSynchronized, which works for the first time you enter a room, but if you leave a room and enter another, cSession.isSynchronized does not do what I'm expecting (true = logging in, false = logging out). Which isSynchronized should I be monitoring? Here's an example of what I'm currently doing and some associated output that is not doing what I expect. I know that looking at cSession.isSynchronized, but could you show me how to modify my example to work correctly?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:rtc="AfcsNameSpace"
    layout="horizontal"
    creationComplete="init()">
   
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import com.adobe.rtc.events.UserEvent;
           
            protected static const roomUrlBase:String = "https://connectnow.acrobat.com/MYACCOUNT/"
           
            protected function init():void {
                cSession.userManager.addEventListener(UserEvent.SYNCHRONIZATION_CHANGE, syncChange);
            }   
           
            protected function syncChange(event:UserEvent):void {
                trace(">> syncChange cSession.isSynchronized = " + cSession.isSynchronized);
            }   
           
            protected function enterRoom():void {
                trace(">> Clicked 'Enter Room' button. Entering room: " + roomField.text);
                trace(">> enterRoom before anything - cSession.isSynchronized = " + cSession.isSynchronized);
                cSession.roomURL = roomUrlBase + roomField.text;
                cSession.login();
            }
           
            protected function leaveRoom():void {
                trace(">> Clicked 'Leave Room' button");
                trace(">> leaveRoom before anything - cSession.isSynchronized = " + cSession.isSynchronized);
                cSession.logout();
            }
        ]]>
    </mx:Script>
       
    <mx:TextInput id="roomField"/>
    <mx:Button label="Enter Room" click="enterRoom()"/>
    <mx:Button label="Leave Room" click="leaveRoom()"/>
    <rtc:ConnectSessionContainer id="cSession" autoLogin="false" width="100%" height="100%" >
        <rtc:authenticator>
            <rtc:AdobeHSAuthenticator userName="Guest"/>
        </rtc:authenticator>
        <rtc:Roster width="250" height="250"/>
    </rtc:ConnectSessionContainer>

</mx:Application>

Output:
>> Clicked 'Enter Room' button. Entering room: myfirstroom1

>> enterRoom before anything - cSession.isSynchronized = false
>> syncChange cSession.isSynchronized = true
>> Clicked 'Leave Room' button
>> leaveRoom before anything - cSession.isSynchronized = true
>> syncChange cSession.isSynchronized = false
>> Clicked 'Enter Room' button. Entering room: myfirstroom2
>> enterRoom before anything - cSession.isSynchronized = false
>> syncChange cSession.isSynchronized = false

Avatar

Former Community Member

1) I didn’t talk about SharedManager/SharedModel example but rather source code classes under com/adobe/rtc/sharedModel and com/adobe/rtc/sharedManager/ ... In these source classes, you may see many files that use synchronization change event with isSynchronized property.

You will find source under your unzipped folder's com.adobe.afcs/libs/player9/src/ .

2) I will run the other part of code and get back to you by end of day.

Thanks

Hironmay Basu

Avatar

Former Community Member

Hi,

I ran your code and I got the mistake you were doing . You were listening to cSession.userManager.addEventListener(UserEvent.SYNCHRONIZATION_CHANGE, syncChange); and then tracing out cSession.isSynchronized and not cSession.userManager.isSynchornized. So, you were not getting coherent results. The reason being, the connectsession synchronization event is fired when everything gets synchronized , and at some point your userManager might have been synchronized but the whole session had not.

Since you are using this event to get into the room and out of it, you should use ConnectSession's SynchronizationChange event and not the userManager's. And that would be SessionEvent and not UserEvent.

Here are the changes you need to do

protected function init():void {

cSession.addEventListener(SessionEvent.SYNCHRONIZATION_CHANGE, syncChange);

}

protected function syncChange(event:SessionEvent):void {

trace(">> syncChange cSession.isSynchronized = " + cSession.isSynchronized);

}

Everything will work fine then. Sorry for not getting back on Friday night , it just slipped off my mind.

Hope this helps

Thanks

Hironmay Basu

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] ----