Download presentation
Presentation is loading. Please wait.
Published byLizbeth Ophelia Fitzgerald Modified over 9 years ago
1
® Developing Plugins for SameTime Connect 7.5 Jian Min JIANG jiangjm@cn.ibm.com Lotus ISV Technical Enablement China Software Development Lab
2
2 Where can see ST Services?
3
3 Sametime Community Server Toolkit Server Application Service logging in and logging outlogging in and logging out sending administrator messages Channel Service communication with other Sametime entities via a proprietary protocol Community Events Service receiveing a variety of events from the community server General Awareness Service change the online attributes of the server Places Admin Service administering the Places server application Places Activity Service writing activity providers to a Sametime place Server Application Storage Service storing user-related information as attributes directly on the Sametime server Light Login Service MUX application to multiplex a connection to the server Server Application Token Service generating a token that can be used to log in as a user to Sametime Online Directory Service locate users and groups in the community
4
4 OfflineMessages Sample (Sametime Server App) The application allows clients to send messages to a user who is currently offline The message is saved and then transferred to its intended recipient when that user goes online Details: When a message to a user who is offline is received, the message is saved together with details about both the sender and the intended receiver. The server application then waits for the receiver to log in. When the receiver logs in to Sametime, the server application logs in on behalf of the sender, sends the message, and immediately logs out.
5
5 Components are used in the sample ServerAppService Used for logging in to the Sametime community as a server application ChannelService Used for receiving channels from clients CommunityEventsService Used for getting notifications on users that log in to the Sametime community LightLoginService Used for logging in on behalf of the message sender SATokenService Used for getting the sender login token InstantMessagingService Used for sending an instant message (IM)
6
6 Initialization public OfflineMessagesSA() { String hostName="isvserver.lotus.com"; // Create and load the session of components. try { m_session = new STSession("OfflineMessages2"); String [] compNames = { ServerAppService.COMP_NAME, CommunityEventsComp.COMP_NAME, SATokenComp.COMP_NAME }; m_session.loadComponents( compNames ); m_session.start(); } catch(DuplicateObjectException e) { e.printStackTrace(); exit(); } m_hostName = hostName; // Get a reference to the needed components. m_commEvents = (CommunityEventsService)m_session.getCompApi(CommunityEventsService.COMP_NAME); m_commEvents.addUserLoginListener(this); ChannelService channelService = (ChannelService)m_session.getCompApi(ChannelService.COMP_NAME); channelService.addChannelServiceListener(this); login(hostName); } UserLoginListener ChannelServiceListener
7
7 Login as a server application void login(String hostName) { ServerAppService saService = (ServerAppService)m_session.getCompApi(ServerAppService.COMP_NAME); short loginType = STUserInstance.LT_SERVER_APP; int[] supportedServices = { SERVICE_TYPE }; // Server applications login directly to the server, and not through // the mux. So we can't use the default port. Connection[] connections = { new SocketConnection(1516, 17000), }; saService.setConnectivity(connections); saService.addLoginListener(this); saService.loginAsServerApp(hostName, loginType, "OfflineMessages2", supportedServices); }
8
8 Implementing the Channel Listener public void channelReceived(ChannelEvent event) { // Get the incoming data. Channel cnl = event.getChannel(); try { NdrInputStream inStream = new NdrInputStream(cnl.getCreateData()); STId receiverId = new STId(inStream); String receiverName = inStream.readUTF(); String message = inStream.readUTF(); STUserInstance sender = cnl.getRemoteInfo(); STUser receiver = new STUser(receiverId, receiverName, ""); UsersHandler handler = new UsersHandler(m_session, m_hostName, cnl.getRemoteInfo(), receiver, message); m_watchedUsers.put(receiverId.getId(), handler); }
9
9 Implementing the Community Events Service public void userLoggedIn (UserLoginEvent event) { // Check if we are interested in this user. STUser user = event.getUserInstance(); System.out.println("userLoggedIn:"+user.getDisplayName()); Object o = m_watchedUsers.remove(user.getId().getId()); if (o != null) { ((UsersHandler)o).receiverOnline(); }
10
10 UserHandler Object – Message Handling Uses the SATokenService to get the sender’s login token Uses the LightLoginService to perform a virtual login on behalf of the sender Uses the InstantMessagingService to send an IM to the receiver with the message Uses the LightLoginService to log out
11
11 Plugin for sending offline messages UI Menu item Dialog to input message
12
12 Plugin.xml <extension point="org.eclipse.ui.popupMenus"> <objectContribution adaptable="false" id="com.devworks.example.offlinemessage.prersonselection" objectClass="com.ibm.collaboration.realtime.livenames.PersonSelection"> <action class="com.devworks.example.offlinemessage.OfflineMessageDelegate" enablesFor="1" id="com.devworks.example.offlinemessage.OfflineMessageDelegate" label="OfflineMessage" style="push" menubarPath="im_chat"/>
13
13 Initializing services private void initializechannelService() { try { CommunityServiceInternal csi = (CommunityServiceInternal) ServiceHub.getService(CommunityServiceInternal.SERVICE_TYPE); Community dc = csi.getDefaultCommunity(); rtcs = dc.getRtcSession(); Field fsession = rtcs.getClass().getDeclaredField("_session"); fsession.setAccessible(true); m_session = (STSession) fsession.get(rtcs); m_channelService = (ChannelService) m_session.getCompApi(ChannelService.COMP_NAME); } catch (SecurityException e1) { e.printStackTrace(); } (how to access Java Toolkit APIs in plugin)
14
14 Sending offline messages by channel service public void send() { m_channelService = Activator.getDefault().getchannelService(); sendOfflineMessage(); } private void sendOfflineMessage() { STId stid = new STId(person.getContactId(), ""); STUser user = new STUser(stid, person.getDisplayName(), ""); NdrOutputStream outStream = new NdrOutputStream(); try { user.getId().dump(outStream); outStream.writeUTF(user.getName()); outStream.writeUTF(msg); } catch (IOException e) { e.printStackTrace(); } try { Channel channel = m_channelService.createChannel(SERVICE_TYPE, 0, 0, EncLevel.ENC_LEVEL_ALL, outStream.toByteArray(), user.getId()); channel.open(); } catch (Exception e) { e.printStackTrace(); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.