Exemple #1
0
        /// <summary>
        /// Terminates a call.
        /// </summary>
        /// <param name="reason">Call termination reason. This text is sent to remote-party.</param>
        public void Terminate(string reason)
        {
            lock (m_pLock){
                if (this.State == SIP_CallState.Disposed)
                {
                    throw new ObjectDisposedException(this.GetType().Name);
                }

                if (this.State == SIP_CallState.Terminating || this.State == SIP_CallState.Terminated)
                {
                    return;
                }
                else if (this.State == SIP_CallState.Active)
                {
                    SetState(SIP_CallState.Terminating);

                    m_pDialog.Terminate(reason, true);
                }
                else if (this.State == SIP_CallState.Calling && m_pInitialInviteSender != null)
                {
                    /* RFC 3261 15.
                     *  If we are caller and call is not active yet, we must do following actions:
                     *) Send CANCEL, set call Terminating flag.
                     *) If we get non 2xx final response, we are done. (Normally cancel causes '408 Request terminated')
                     *) If we get 2xx response (2xx sent by remote party before our CANCEL reached), we must send BYE to active dialog.
                     */

                    SetState(SIP_CallState.Terminating);

                    m_pInitialInviteSender.Cancel();
                }
            }
        }
        /// <summary>
        /// Starts terminating call. To get when call actually terminates, monitor <b>StateChanged</b> event.
        /// </summary>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception>
        public void Terminate()
        {
            lock (m_pLock)
            {
                if (m_State == SIP_UA_CallState.Disposed)
                {
                    throw new ObjectDisposedException(GetType().Name);
                }

                if (m_State == SIP_UA_CallState.Terminating || m_State == SIP_UA_CallState.Terminated)
                {
                    return;
                }
                else if (m_State == SIP_UA_CallState.WaitingForStart)
                {
                    SetState(SIP_UA_CallState.Terminated);
                }
                else if (m_State == SIP_UA_CallState.WaitingToAccept)
                {
                    m_pInitialInviteTransaction.SendResponse(
                        m_pUA.Stack.CreateResponse(SIP_ResponseCodes.x487_Request_Terminated,
                                                   m_pInitialInviteTransaction.Request));

                    SetState(SIP_UA_CallState.Terminated);
                }
                else if (m_State == SIP_UA_CallState.Active)
                {
                    m_pDialog.Terminate();

                    SetState(SIP_UA_CallState.Terminated);
                }
                else if (m_pInitialInviteSender != null)
                {
                    /* RFC 3261 15.
                     *  If we are caller and call is not active yet, we must do following actions:
                     *) Send CANCEL, set call Terminating flag.
                     *) If we get non 2xx final response, we are done. (Normally cancel causes '408 Request terminated')
                     *) If we get 2xx response (2xx sent by remote party before our CANCEL reached), we must send BYE to active dialog.
                     */

                    SetState(SIP_UA_CallState.Terminating);

                    m_pInitialInviteSender.Cancel();
                }
            }
        }