After an incoming signaling session is received, an application can accept the incoming session by either calling the Participate method synchronously or by using the BeginParticipate … EndParticipate asynchronous programming pattern. The application can also choose to decline the invitation by calling the Terminate or TerminateWithRejection method.
Accepting a Session INVITE Synchronously
The following code example illustrates the synchronous programming pattern for accepting an incoming signaling session INVITE request.
Copy Code | |
---|---|
SignalingSession session = ...; try { session.Participate(); } catch (RealTimeException exp) { // Handle accept failures. } |
Before accepting a session, an application normally registers for the StateChanged event and sets the desired session properties, such as MediaNegotiation.
Accepting a Session INVITE Asynchronously
The following code example illustrates the asynchronous programming pattern for accepting an incoming signaling session INVITE request. Following the call to BeginParticipate, the invitee should catch InvalidOperationException, which can be thrown if the inviter cancels the session before BeginParticipate is called. This can occur even when the application determines that the SignalingState state is Incoming, during race conditions.
Copy Code | |
---|---|
SignalingSession session = ...; try { session.BeginParticipate(new AsyncCallback(this.Accept_Completed), session); } catch (InvalidOperationException exp) { // Handle accept failures. } void Accept_Completed(IAsyncResult asyncResult) { SignalingSession session = (SignalingSession) asyncResult.AsyncState; try { session.EndParticipate(); } catch (FailureResponseException exp) { // Handle a failure response Console.WriteLine("Failure response for {0}: {1}", session.RemoteParticipant.Uri, exp.ToString()); } catch (OperationTimeoutException exp) { // Operation timed out Console.WriteLine("Operation timed out for {0}: {1}", session.RemoteParticipant.Uri, exp.ToString()); } catch (RealTimeException exp) { // Handle exception. Console.WriteLine("Invite Failure for {0}: {1}", session.RemoteParticipant.Uri, exp.ToString()); } } |
It is possible for the participate operation to fail.
Possible reasons are that the inviter is no longer available or
that the inviter has cancelled the session. An application can
determine whether the accept operation completed successfully by
using try .
..
catch
...
blocks around Participate or
BeginParticipate...EndParticipate.
Declining a Session INVITE
The following code example illustrates the programming pattern for declining a signaling session INVITE request.
Copy Code | |
---|---|
SignalingSession session = ...; // an incoming session just received session.TerminateWithRejection(ResponseCode.NotAcceptableHere, null); |
An application can provide some custom headers in the call.
Alternatively, the application can also call Terminate on an incoming session to decline the invitation. As with TerminateWithRejection, custom headers can be passed in the call.