Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Dynamically switching rooms

Avatar

Level 3
Can someone walk me through the process of dynamically
connecting a SessionContainer/pod(s) to a new room "on the fly".



Many thanks,



Rick

5 Replies

Avatar

Employee
You can try:



sessionContainer.logout()

sessionContainer.roomURL = newRoomURL



// possibly change user new room owner

auth.userName = newUserName

aut.password = newPassword



// login into new room

sessionContainer.login()



Avatar

Level 3
Hi, Raff.



That's what I had already tried, but the pods don't re-synch
to the new room. In looking at the source for the chat pod, it
looks like the model doesn't get set to null on close/disconnect,
and this seems to be causing issues.



Unfortunately, the _model member is read-only (only provides
a getter) so I couldn't force it to null to see if that was the
issue.



Rick





Avatar

Level 2
Here's what I ended up using to make things work:



1. I created a class of my own called ExtendedSimpleChat,
which extends SimpleChat



2. I added an "unsubscribe" method (shown below) to this
class, which disconnects and destroys the existing model and
userManager instances in the SimpleChat class (and clears the
history and message input UI objects)



3. To switch rooms, I call the following methods (cSession is
the ConnectSessionContainer instance)



chatPod.unsubscribe();

cSession.logout();

cSession.roomURL = "new URL goes here";

cSession.login();



4. In the event handler for
SessionEvent.SYNCHRONIZATION_CHANGE, if the session is
synchronized, I call:



chatPod.subscribe();



This combination seems to work well. It would probably be a
good idea to add this unsubscribe method to the SimpleChat class.
The "close()" method in SimpleChat disconnects too many other
things.





-------------------------------------------------------------------------------------

public function unsubscribe() : void {

if (_model) {

_model.close();


_model.removeEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE,
onSynchronizationChange);

_model.removeEventListener(ChatEvent.HISTORY_CHANGE,
onHistoryChange);

_model.removeEventListener(ChatEvent.TYPING_LIST_UPDATE,
onTypingListUpdate);


_model.removeEventListener(ChatEvent.ALLOW_PRIVATE_CHAT_CHANGE,
onAllowPrivateChange);



_model = null;

}



if(_userManager) {

_userManager.removeEventListener(UserEvent.USER_CREATE,
dirtyUserList);

_userManager.removeEventListener(UserEvent.USER_REMOVE,
onUserRemove);

_userManager.removeEventListener(UserEvent.USER_ROLE_CHANGE,
onUserRoleChange);



_userManager = null;

}



_history.htmlText = "" ;

_newMessage.text = "" ;



}



Avatar

Former Community Member


Hi Rick,



Interesting - the idea here definitely was for "close()" on
the SimpleChatModel to do the work here, and for you to be able to
call chatPod.subscribe() again, I appreciate the time you took to
figure out what wasn't working here - we'll definitely take what
you've hit here and make some improvements to the class to make
this smoother.



I love it when people start doing things with our classes
that we hadn't yet had time to try ourselves! Progress!



thanks

nigel

Avatar

Level 2
Hi, Nigel.



HTH. Rest assured, we'll try to do plenty of things you
haven't had a chance to try yet... ;-)



Happy holidays,



Rick