示例#1
0
        public void OnIncomingCall(IncomingCallRecieved e)
        {
            Account account = _accMgr.GetAccount(e.AccountId);
            if (account == null) // || !account.IsRegistered)
                account = _accMgr.GetAccount(_accMgr.DefaultAccount.Id);

            _logger.DebugFormat("incoming call for account {0}", account.AccountId);

            if (account != null)
            {
                Monitor.Enter(_lock);
                if (_activeCalls.Count < MaxCalls)
                {
                    var call = _objectFactory.Create<Call>();
                    using (call.InitializationScope())
                    {
                        call.SetId(e.CallId);
                        call.SetAccount(account);
                        call.SetAsIncoming();
                    }
                    AddCallAndUpdateEaCache(account.AccountId, call);
                    Monitor.Exit(_lock);
                    if (_localRegistry.Config.AutoAnswer)
                    {
                        call.Answer(true);
                        if (_activeCalls.Count > 0)
                            _barrier.Reset();
                        return;
                    }

                    RaiseRingEvent(call, true);
                    var ea = new EventArgs<ICall>(call);
                    IncomingCall(this, ea);

                    if (_activeCalls.Count > 0)
                        _barrier.Reset();
                }
                else
                {
                    Monitor.Exit(_lock);
                    _callApi.AnswerCall(e.CallId, SipStatusCode.Decline, "Too much calls");
                }
            }
        }
        public void OnIncomingCall(IncomingCallRecieved e)
        {
            IAccountInternal account = _accMgr.GetAccount(e.AccountId);
            if (account == null) // || !account.IsRegistered)
                account = _accMgr.GetAccount(_accMgr.DefaultAccount.Id);

            _logger.DebugFormat("incoming call for account {0}", account.AccountId);

            if (account != null)
            {
                Monitor.Enter(_lock);
                if (_activeCalls.Count < MaxCalls)
                {
                    var call = _objectFactory.Create<ICallInternal>();
                    using (call.InitializationScope())
                    {
                        call.SetId(e.CallId);
                        call.SetAccount(account);
                        call.SetAsIncoming();
                    }
                    AddCallAndUpdateEaCache(account.AccountId, call);
                    Monitor.Exit(_lock);
                    if (_localRegistry.Config.AutoAnswer)
                    {
                        call.Answer(true);
                        if (_activeCalls.Count > 0)
                            _barrier.Reset();
                        return;
                    }

                    RaiseRingEvent(call, true);
                    var ea = new EventArgs<ICall>(call);
                    //try
                    //{
                    //    if (_syncContext != null)
                    //        _syncContext.Post(delegate { IncomingCall(this, ea); }, null);
                    //    else
                    //        IncomingCall(this, ea);
                    //}
                    //catch (InvalidOperationException)
                    //{
                    IncomingCall(this, ea);
                    //}

                    if (_activeCalls.Count > 0)
                        _barrier.Reset();
                }
                else
                {
                    Monitor.Exit(_lock);
                    //Don't have to create an object here - simply closing this session
                    _callApi.AnswerCall(e.CallId, SipStatusCode.Decline, "Too much calls");
                }
            }
        }