Beispiel #1
0
        /// <inheritdoc />
        protected override async Task InternalExecute(Channel userChannel, StasisStartEventArgs args)
        {
            var routeData = args.RouteData;

            if (!routeData.FromCallId.HasValue)
            {
                Logger.Warning($"Id вызова пользователя не задан. ChannelId: {userChannel.Id}");
                return;
            }

            var userExtension        = routeData.FromExtension;
            var destinationExtension = routeData.ToExtension;
            var destinationChannelId = AriClient.CreateChannelId(ChannelRoleType.ExternalChannel, destinationExtension);

            var bridge = await AriClient.CreateBridge();

            await AriClient.AddChannelToBridge(bridge.Id, userChannel.Id);

            var playBackId = await AriClient.PlayBeeps(userChannel.Id);

            var destinationCallArgs = new StasisStartEventArgs
            {
                BridgeId   = bridge.Id,
                EventType  = StasisStartEventType.CallToDestination,
                RouteData  = routeData,
                PlaybackId = playBackId
            };

            var encodedArgs     = JsonSerializer.EncodeData(destinationCallArgs);
            var originateResult = await AriClient.Originate(encodedArgs, "Служба 112", destinationExtension, destinationChannelId);

            if (!originateResult)
            {
                throw new Exception("Ошибка создания канала для участника разговора, которому звонит пользователь.");
            }

            var userChannelEntity = new DAL.Entities.Channel
            {
                ChannelId = userChannel.Id,
                Extension = userExtension,
                CallId    = routeData.FromCallId.Value,
                BridgeId  = bridge.Id,
                Role      = ChannelRoleType.Conference,
                LineId    = routeData.LineId
            };
            await ChannelRepository.AddChannel(userChannelEntity);

            var destinationChannelEntity = new DAL.Entities.Channel
            {
                ChannelId = destinationChannelId,
                Extension = destinationExtension,
                CallId    = routeData.ToCallId,
                BridgeId  = bridge.Id,
                Role      = ChannelRoleType.RingingFromUser,
                LineId    = routeData.LineId
            };
            await ChannelRepository.AddChannel(destinationChannelEntity);
        }