Beispiel #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 ICall MakeCall(IAccount account, string destinationUri)
        {
            lock (_lock)
            {
                Helper.GuardNotNull(account);
                Helper.GuardInRange(0u, MaxCalls - 1, (uint)_activeCalls.Count);

                var result = _objectFactory.Create <ICallInternal>();
                var acc    = _accMgr.GetAccount(account.Id);
                Helper.GuardNotNull(acc);
                result.SetAccount(acc);
                using (result.InitializationScope())
                    result.SetDestinationUri(destinationUri);

                result.SetId(_callApi.MakeCallAndGetId(result.Account.Id, destinationUri, 0));
                AddCallAndUpdateEaCache(destinationUri, result);

                result.HandleInviteStateChanged();

                _barrier.Reset();
                return(result);
            }
        }