Example #1
0
        /// <inheritdoc />
        protected override async Task InternalExecute(Channel userChannel, StasisStartEventArgs args)
        {
            Logger.Information($"AcceptIncomingCallCommand. UserChannelId: {userChannel.Id}, IncomingChannelId: {args.ChannelId}");

            try
            {
                var incomingCallChannel = await ChannelRepository.GetByChannelId(args.ChannelId);

                if (incomingCallChannel == null)
                {
                    Logger.Warning($"Канал входящего вызова не найден. UserChannelId: {userChannel.Id}");
                    return;
                }

                var routeData = args.RouteData;
                var lineId    = routeData.LineId;

                await InitializeRecordingChannel(userChannel.Id, routeData.ToExtension, ChannelRoleType.Conference, incomingCallChannel.BridgeId, routeData.ToCallId, lineId);

                await AriClient.UnholdAsync(incomingCallChannel.ChannelId);

                await AriClient.StopMohInBridgeAsync(incomingCallChannel.BridgeId);

                await AriClient.AddChannelToBridge(incomingCallChannel.BridgeId, userChannel.Id);

                incomingCallChannel.Interrupted = false;
                incomingCallChannel.LineId      = lineId;
                await ChannelRepository.UpdateChannel(incomingCallChannel);

                await UpdateAudioRecords(incomingCallChannel.BridgeId, incomingCallChannel.CallId, lineId);

                var userChannelEntity = new DAL.Entities.Channel
                {
                    ChannelId = userChannel.Id,
                    BridgeId  = incomingCallChannel.BridgeId,
                    CallId    = routeData.ToCallId,
                    Extension = routeData.ToExtension,
                    Role      = ChannelRoleType.Conference,
                    LineId    = lineId
                };
                await ChannelRepository.AddChannel(userChannelEntity);
            }
            catch (Exception ex)
            {
                Logger.Warning("AcceptIncomingCallCommand Error", ex);
            }
        }