Expand my Community achievements bar.

SOLVED

SimpleChatModel problem

Avatar

Level 1

I am stuck on a problem I am having with the SimpleChatModel. If I log into the ConnectSession and then create my SimpleChatModel everything works fine. However, if in the same flash session (no browser refresh) I disconnect from LCCS (logout from the connected session, remove all listeners and null all vars) then reconnect successfully and create a new SimpleChatModel, I never get the SYNCHRONIZATION_CHANGE event on the new SimpleChatModel. I see the reconnected user in the admin console but that user can't chat.

1 Accepted Solution

Avatar

Correct answer by
Employee

Adding this line at line number 43 should fix the issue.

chatModel.connectSession = cSession;

protected function buildModel():void
{
     chatModel = new SimpleChatModel();
     chatModel.sharedID = "simpleChat";
        chatModel.addEventListener(ChatEvent.HISTORY_CHANGE, onChatMsg);
     chatModel.addEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE, onSync);
     chatModel.connectSession = cSession;
     chatModel.subscribe();
}

What was happening was that,

1) When you login the first time, the ConnectSession created during that time is also assigned as ConnectSession.primarySession.

2) When you logout , you are logging out of both the ConnectSession.primarySession and connectSession (cSession) you created.

3) When you login again, you are creating a new instance of ConnectSession and logging into it. But your ConnectSession.primarySession was logged out.

4) So the SimpleChatModel was using the ConnectSession.primarySession as it wasnt assigned the new ConnectSession you created. As a result the SimpleChatModel was not able to subscribe.

So the solution is to set the new ConnectSession to your SimpleChatModel or dont discard your ConnectSession. Instead just login and logout of the first ConnectSession instance you create.

Hope I have been able to explain what was happening.

Thanks

Arun

View solution in original post

9 Replies

Avatar

Former Community Member

Hello gort,

Are you calling "subscribe()" on the simpleChatModel the second time around?

nigel

Avatar

Level 1

Yes, is that a problem.

Every time a user is gets the ACCEPT event from the knockingQueue I do something like this.

chat_model = new SimpleChatModel(true);
chat_model.sharedID = "my_chatModel";
chat_model.addEventListener(ChatEvent.HISTORY_CHANGE, onChatMessage);
chat_model.addEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE, onChatSyncChange);
chat_model.subscribe();

Avatar

Employee

Hi,

Can you please attach your entire code if possible. I checked the behaviour you mentioned by modifying the SimpleChatExample (code attached) provided in SampleApps. And I do get a CollectionNodeEvent.SYNCHRONIZATION_CHANGE event every time I login and logout.

Thanks

Arun

Avatar

Level 1

I'm not able to post the entire code right now. It's probably too complicated to be useful. I'll try to slim it down to a simple example.

The big difference I can see between your code and mine is I am creating a new ConnectSession each time with a new authenticator.

Avatar

Level 1

Sorry for the double post. See next message with example code attached.

Avatar

Level 1

Ok, I modified your modification of the SimpleChatExample to demonstrate the problem I am seeing. To recreate, click the "login" button once. You will see in the trace statements the login is successful then the SimpleChatModel is created and synchronized (SYNCHRONIZATION_CHANGE fires). Now logout and everything is set to null and listeners are removed. Now try to login again. This time when the SimpleChatModel is created the event never fires and chatting will not work.

You will need to set your own user name, password and room to run the example.

Thanks

Avatar

Correct answer by
Employee

Adding this line at line number 43 should fix the issue.

chatModel.connectSession = cSession;

protected function buildModel():void
{
     chatModel = new SimpleChatModel();
     chatModel.sharedID = "simpleChat";
        chatModel.addEventListener(ChatEvent.HISTORY_CHANGE, onChatMsg);
     chatModel.addEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE, onSync);
     chatModel.connectSession = cSession;
     chatModel.subscribe();
}

What was happening was that,

1) When you login the first time, the ConnectSession created during that time is also assigned as ConnectSession.primarySession.

2) When you logout , you are logging out of both the ConnectSession.primarySession and connectSession (cSession) you created.

3) When you login again, you are creating a new instance of ConnectSession and logging into it. But your ConnectSession.primarySession was logged out.

4) So the SimpleChatModel was using the ConnectSession.primarySession as it wasnt assigned the new ConnectSession you created. As a result the SimpleChatModel was not able to subscribe.

So the solution is to set the new ConnectSession to your SimpleChatModel or dont discard your ConnectSession. Instead just login and logout of the first ConnectSession instance you create.

Hope I have been able to explain what was happening.

Thanks

Arun

Avatar

Level 1

It works as expected now. Thank you Arun.