Accept an Incoming Application Session

The following code examples demonstrate how to accept an incoming application session (RTCST_APPLICATION). The operations in the Initialize RTC code example must be performed before using this example.

Note  This example does not contain error checking or releases appropriate for real code.

C++ Code Example

IRTCSession2    *pIRTCSession2          = NULL;
BSTR            bstrContentType         = SysAllocString(L"application/sdp");
BSTR            bstrSessionDescription  = // Specify the Session Description ;

// Note: For applications that have initialized the 
// stack by calling IRTCClient:Initialize(), the 
// following operations must be performed before 
// receiving an incoming RTCST_APPLICATION type 
// session.
// 1) The application must implement the 
// IRTCSessionDescriptionManager interface and call
// IRTCClient2::SetSessionDescriptionManager(), passing   
// in the pointer to the IRTCSessionDescriptionManager 
// interface.
// 2) The RTC Client API will then call into the 
// IRTCSessionDescriptionManager::EvaluateSessionDescription() 
// callback to supply the application with the content type 
// and session description.
// 3) The application returns the pfApplicationSession 
// parameter (in EvaluateSessionDescription) as 
// VARIANT_TRUE, indicating the application's decision to  
// accept the incoming application session.
// 4) The application waits for the RTCE_SESSION_STATE_CHANGE 
// event of type RTCSS_INCOMING, then answers the session as 
// shown below.

// Note: For applications that initialized the stack by  
// calling the IRTCClient2:InitializeEx(RTCIF_DISABLE_MEDIA) 
// method, the application waits for the RTCE_SESSION_STATE_CHANGE 
// event of type RTCSS_INCOMING before answering the session as
// shown below.

// Wait for the RTCE_SESSION_STATE_CHANGE event of type 
// RTCSS_INCOMING. Get the IRTCSession pointer from 
// IRTCSessionStateChangeEvent and then QI for the 
// IRTCSession2 interface.

// Accept the incoming application session.
hr = pIRTCSession2->AnswerWithSessionDescription(bstrContentType,
                                                 bstrSessionDescription);

// If (hr != S_OK), process the error here. 

// Wait for the RTCE_SESSION_STATE_CHANGE event of type 
// RTCSS_CONNECTED before performing operations
// on the session. 

Visual Basic Code Example

' 2. Accept an incoming RTCST_APPLICATION session.

Dim objSession2 As IRTCSession2
Dim strContentType As String            '(for example, application/sdp)
Dim strSessionDescription As String     '(Specify the Session Description)

' Note: For applications that have initialized the 
' stack by calling IRTCClient:Initialize(), the 
' following operations must be performed before 
' receiving an incoming RTCST_APPLICATION type 
' session.
' 1) The application must implement the 
' IRTCSessionDescriptionManager interface and call
' IRTCClient2::SetSessionDescriptionManager(), passing   
' in the pointer to the IRTCSessionDescriptionManager 
' interface.
' 2) The RTC Client API will then call into the 
' IRTCSessionDescriptionManager::EvaluateSessionDescription() 
' callback to supply the application with the content type 
' and session description.
' 3) The application returns the pfApplicationSession 
' parameter (in EvaluateSessionDescription) as 
' VARIANT_TRUE, indicating the application's decision to  
' accept the incoming application session.
' 4) The application waits for the RTCE_SESSION_STATE_CHANGE 
' event of type RTCSS_INCOMING, then answers the session as 
' shown below. 

' To implement the IRTCSessionDescriptionManager interface in VB6, 
' the application creates a class file (.cls) with the following 
' boilerplate code. The application can then add the relevant 
' code to the EvaluateSessionDescription() implementation and  
' pass an instance of this class object to 
' IRTCClient2::SetSessionDescriptionManager(). 

Implements IRTCSessionDescriptionManager                                                                    
                                                                                                                                                                                                                       
Private Sub IRTCSessionDescriptionManager_EvaluateSessionDescription(ByVal bstrContentType As String, _     
                                                                     ByVal bstrSessionDescription As String,
                                                                     pfApplicationSession As Boolean)       
    ' Add your code here.
    pfApplicationSession = True
End Sub

' Note: For applications that initialized the stack by  
' calling the IRTCClient2:InitializeEx(RTCIF_DISABLE_MEDIA) 
' method, the application waits for the RTCE_SESSION_STATE_CHANGE 
' event of type RTCSS_INCOMING before answering the session as
' shown below.

' Wait for the RTCE_SESSION_STATE_CHANGE event of type 
' RTCSS_INCOMING. Get the IRTCSession pointer from 
' IRTCSessionStateChangeEvent and then query
' for the IRTCSession2 interface.

' Accept the incoming application session.
objSession2.AnswerWithSessionDescription(strContentType, _
                                         strSessionDescription)

' If (Err.Number), process the error here. 

' Wait for the RTCE_SESSION_STATE_CHANGE event of 
' type RTCSS_CONNECTED before performing operations 
' on the session.