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

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

Login process using RTC 1.3 API (VB.NET)

This article demonstrates the process of logging into Live Communications Server (also known as Office Communication Server) using RTC 1.3 API.
 Step1: Add references to RTC 1.3 to the project
 Step2: Declare the following variables:
     Dim _IRTCClient2 As RTCCORELib.IRTCClient2
     Dim WithEvents _RTCClient As RTCCORELib.RTCClient
     Dim _IRTCClientPresence2 As RTCCORELib.IRTCClientPresence2
     Dim _IRTCClientProvisioning2 As RTCCORELib.IRTCClientProvisioning2
     Dim _IRTCProfile2 As RTCCORELib.IRTCProfile2
     Dim _lngFlag As Long
     Dim _ProfileFilePath As String = ""
 Step3: Initialize the RTCClient object in the class constructor
     Public Sub New()
         On Error Resume Next
         _IRTCClient2 = New RTCCORELib.RTCClient
         Call _IRTCClient2.InitializeEx(_lngFlag)
         _IRTCClient2.EventFilter = 33554431 'To receive all server events
         _IRTCClient2.ListenForIncomingSessions = RTCCORELib.RTC_LISTEN_MODE.RTCLM_BOTH
         _IRTCClientPresence2 = _IRTCClient2
         _IRTCClientProvisioning2 = _IRTCClient2
         _RTCClient = _IRTCClient2
     End Sub
 Step4: Use the authentication details to sign in the Server
     Public Sub login(ByVal serverip As String, ByVal username As String, ByVal password As String, ByVal signInName As String, ByVal transport As String)
             Dim ProtocolType As Integer
             If transport = "TLS" Then
                 ProtocolType = 4
                 ProtocolType = 2
             End If
             Call _IRTCClientProvisioning2.GetProfile(username, password, signInName, serverip, ProtocolType, 0)
         Catch ex As Exception
             Trace.WriteLine("Error: " & ex.ToString, "Error")
         End Try
     End Sub
 Step5: Wait for the server response in RTCClient Event
     Private Sub _RTCClient_Event(ByVal RTCEvent As RTCCORELib.RTC_EVENT, ByVal pEvent As Object) Handles _RTCClient.Event
             Select Case RTCEvent
                 Case RTCCORELib.RTC_EVENT.RTCE_CLIENT
                     Call ClientEvent(pEvent)
                     Call RegistrationStateChangeEvent(pEvent)
                     Call ProfileEvent(pEvent)
             End Select
         Catch ex As Exception
             Trace.WriteLine("Error: " & ex.ToString, "Error")
         End Try
     End Sub
 Step6: Profile event will fire if user login is successful. After successful login enable user profile and presence on the server
     Private Sub ProfileEvent(ByVal pEvent As RTCCORELib.IRTCProfileEvent2)
     'Called if user has successfully logged in
         On Error Resume Next
         Select Case pEvent.EventType
                 'Profile retrieved successfully
                 If pEvent.StatusCode = 0 Then
                     _IRTCProfile2 = pEvent.Profile
                     ProfileFilePath = "Any String"
                     Call _IRTCClientPresence2.EnablePresenceEx(_IRTCProfile2, ProfileFilePath, 0) 'Enable presence
                     Call _IRTCClientProvisioning2.EnableProfileEx(_IRTCProfile2, 15, 15) 'Enable profile
                 End If
         End Select
     End Sub
 Step7: Signing out of the server. For signing out disable profile and prepare RTC Client for shutdown
     Public Sub logout()
         On Error Resume Next
         Call _IRTCClientProvisioning2.DisableProfile(_IRTCProfile2)
         Call _IRTCClient2.PrepareForShutdown()
     End Sub
 Step8: Registration State event will notify if sign-in failed
     Private Sub RegistrationStateChangeEvent(ByVal pEvent As RTCCORELib.IRTCRegistrationStateChangeEvent)
         On Error Resume Next
         Select Case pEvent.State
                 'Reason: Registration Rejected
                 Call m_IRTCClientPresence2.DisablePresence()
                 'Reason: Normal Logout
                 Select Case pEvent.StatusCode
                     Case -2131820140
                         'Invalid Sip Uri
                     Case -2131820143
                         'Invalid Password/UserName
                     Case -2131885977
                         'Failed to make TCP/IP connection. Server Not Found
                     Case -2131885954
                         ' UDP not supported
                     Case -2131886052
                         ' cannot connect using TLS (SSL connection to HTTP proxy)
                     Case Else
                         ' login unsuccessfull return Error Code
                 End Select
                 'Reason: Normal Logout
             End Select
     End Sub
 Step9: Client event will notify if application has logged out cleanly
     Private Sub ClientEvent(ByVal pEvent As RTCCORELib.IRTCClientEvent)
         'Called when Client State Changes
         On Error Resume Next
         Select Case pEvent.EventType
         End Select
     End Sub

Print | posted on Tuesday, June 05, 2007 6:11 PM |