IM sessions support multi parties. This article demonstrates the process of creating an IM session and adding participants to the IM session.
Step1: Add reference to RTC 1.3 API to the project
Step2: Login to the LCS server using RTC API. For step by step process refer the article: Login process using RTC 1.3 API (VB.NET)
Step3: Add the following function to create chat session
Public Sub StartChatSession(ByVal ParticipantSipUri As String)
'Start Chat Session
Dim IRTCSession As IRTCSession2
Dim IRTCParticipant As IRTCParticipant
Set IRTCSession = _IRTCClient2.CreateSession(RTCST_MULTIPARTY_IM, vbNullString, _IRTCProfile2, _lngFlag)
Set IRTCParticipant = IRTCSession.AddParticipant(ParticipantSipUri, vbNullString)
End Sub
Step4: After adding the participant in the session wait for event type RTCSS_CONNECTED before performing any other operation on the IM session
Step5: Sending message in IM Session
IRTCSession2.SendMessage("text/plain", Message, _lngFlag)
Step6: Sending Typing status in IM Session
IRTCSession2.SendMessageStatus(RTC_MESSAGING_USER_STATUS.RTCMUS_TYPING, _lngFlag)
Step7: Receiving typing status/message from other participants
To receive typing status/message in an IM session watch for event type RTCE_MESSAGING. Add the following function to process data received in messaging event.
Private Sub MessagingEvent(ByVal pEvent As RTCCORELib.IRTCMessagingEvent)
'Called when a message arrives or when a user is typing message
Dim IRTCParticipant As IRTCParticipant
Dim ParticipantSipUri As String
If _IRTCSession2 Is pEvent.Session Then
ParticipantSipUri = pEvent.Participant.UserURI()
Select Case pEvent.EventType
Case RTC_MESSAGING_EVENT_TYPE.RTCMSET_MESSAGE
'Message received from participant (pEvent.Message)
Case RTC_MESSAGING_EVENT_TYPE.RTCMSET_STATUS
Select Case pEvent.UserStatus
Case RTC_MESSAGING_USER_STATUS.RTCMUS_IDLE
'User is not typing
Case RTC_MESSAGING_USER_STATUS.RTCMUS_TYPING
'User is typing
End Select
End Select
End If
End Sub