Enterprise Instant Messaging (Microsoft Unified Communications , IBM Sametime, Jabber)

Comprehensive Instant Messaging information resource for enterprise IT professionals
posts - 94, comments - 0, trackbacks - 0

Getting STSession in Sametime Connect 7.5.1 client

To use Sametime toolkit in your plug-in you will need STSession of a logged in user. This article specifies the process of getting STSession.

Step1: Add the following dependencies to the plug-in:
    com.ibm.collaboration.realtime.community
    com.ibm.collaboration.rtc.protocols.sametime (for accessing Sametime toolkit classes and interfaces)
    com.ibm.collaboration.realtime.core

Step2: Add the following import statements to the java class file:
    import com.ibm.collaboration.realtime.im.community.Community;
    import com.ibm.collaboration.realtime.im.community.CommunityLifecycleEvent;
    import com.ibm.collaboration.realtime.im.community.CommunityLoginEvent;
    import com.ibm.collaboration.realtime.im.community.CommunityService;
    import com.ibm.collaboration.realtime.im.community.CommunityServiceEvent;
    import com.ibm.collaboration.realtime.im.community.CommunityServiceInternal;
    import com.ibm.collaboration.realtime.im.community.CommunityStatusEvent;
    import com.ibm.collaboration.realtime.im.community.ICommunityListener;

Step3: Class should implement ICommunityListener interface

Step4: Declare the variable: CommunityServiceInternal _CommunityServiceInternal;

Step5: Register _CommunityServiceInternal to get login/logout events
    _CommunityServiceInternal=(CommunityServiceInternal)ServiceHub.getService(CommunityService.SERVICE_TYPE);
    _CommunityServiceInternal.registerCommunityListener(this);

Step6: Now watch handleCommunityLoginEvent() for user login/logout events. Following snippet specifies the process of retrieving STSession
    public void handleCommunityLoginEvent(CommunityLoginEvent loginEvent) {
        try {
                if (loginEvent.getType()==1) //logged In
                {
                    STSession tmpSTSession = (STSession)getCommunityByID(communityID).getRtcSession().getProtocolSession();
                }

                if (loginEvent.getType()==2) //logged Out
                {
                    //m_STSession = null;
                    //TODO:FREE RESOURCES
                }
            } catch (Exception ex){}
    }

    /*
     * Get Community by CommunityID
     */
    public Community getCommunityByID(String communityID) {
        try {
                for (int i=0;i<_CommunityServiceInternal.getAllCommunities().size();i++)
                {
                    Community tmpCommunity = (Community)_CommunityServiceInternal.getAllCommunities().get(i);
                    if (tmpCommunity.getId().equals(communityID))
                    {
                        return tmpCommunity;
                    }
                }
                return null;
            } catch (Exception ex) {
                return null;
            }
    }

Print | posted on Wednesday, May 23, 2007 6:38 PM |