Ejemplo n.º 1
0
        private void OnPhoneCallStopped()
        {
            Check.IsTrue(_isRunning, "Failed to stop the call. The phone can only stop calls while in 'RUNNING' state.");
            Check.Require(_pendingPhoneCall, "The phone has no call pending.");
            Check.IsTrue(InternalState != _stateProvider.GetIdle(), "Failed to stop the call. The phone can only stop calls while not in 'IDLE' state. CurrentState: 'IDLE'");

            if (_logger.IsInfoEnabled)
            {
                _logger.Info("Stopping phonecall... DebugInfo: IsIncoming: '{0}', InternalState: '{1}'", _pendingPhoneCall.IsIncoming, InternalState.GetType().Name);
            }



            if (InternalState == _stateProvider.GetWaitProvisional())
            {
                /*If no provisional response has been received, the CANCEL request MUST
                 * NOT be sent; rather, the client MUST wait for the arrival of a
                 * provisional response before sending the request.*/

                if (_logger.IsInfoEnabled)
                {
                    _logger.Info("The call will automatically be stopped when transitioning to 'WAITFINAL' state. Waiting for transition...");
                }

                PendingInvite.CancelOnWaitFinal = true;
            }
            else if (InternalState == _stateProvider.GetWaitFinal())
            {
                SendCancel();

                if (_logger.IsInfoEnabled)
                {
                    _logger.Info("Phonecall stopped.");
                }

                //TODO: send bye also to prevent possible peer-state race conditions?*/
            }
            else if (InternalState == _stateProvider.GetEstablished())
            {
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("Sending 'BYE'...");
                }

                /*send bye + terminate dialog*/
                var byeRequest = PendingInvite.Dialog.CreateRequest(SipMethods.Bye);
                var byeCtx     = _provider.CreateClientTransaction(byeRequest);
                PendingInvite.Dialog.SendRequest(byeCtx);

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("'BYE' sent.");
                }

                if (_logger.IsInfoEnabled)
                {
                    _logger.Info("Transitioning to 'WAITBYEOK' state...");
                }

                ChangeState(_stateProvider.GetWaitByeOk());

                if (_logger.IsInfoEnabled)
                {
                    _logger.Info("Phonecall stopped.");
                }
            }
            else
            {
                if (_logger.IsInfoEnabled)
                {
                    _logger.Info("Phonecall could not be stopped. DebugInfo: IsIncoming: '{0}', InternalState: '{1}'", _pendingPhoneCall.IsIncoming, InternalState.GetType().Name);
                }
            }
        }
Ejemplo n.º 2
0
        private void OnPhoneCallRejected()
        {
            throw new NotSupportedException(); //TODO: support it.
            Check.IsTrue(_isRunning, "Failed to reject the call. The phone can only reject calls while in 'RUNNING' state.");
            Check.Require(_pendingPhoneCall, "The phone has no call pending.");
            Check.IsTrue(InternalState == _stateProvider.GetRinging(),
                         string.Format("Can not reject the phonecall. The phonecall can only be rejected while in the phone is in 'RINGING state'. Currentstate: '{0}'", InternalState.GetType().Name));

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Rejecting phonecall...");
            }

            var rejectResponse = PendingInvite.OriginalRequest.CreateResponse(SipResponseCodes.x486_Busy_Here);

            PendingInvite.InviteServerTransaction.SendResponse(rejectResponse);

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Phonecall rejected.");
            }
        }