コード例 #1
0
ファイル: BasicChannel.cs プロジェクト: bushadam/NEventSocket
        protected BasicChannel(EventMessage eventMessage, EventSocket eventSocket)
        {
            Log = LogProvider.GetLogger(GetType());

            UUID = eventMessage.UUID;
            lastEvent = eventMessage;
            this.eventSocket = eventSocket;

            Disposables.Add(
                eventSocket.Events
                           .Where(x => x.UUID == UUID)
                           .Subscribe(
                               e =>
                                   {
                                       lastEvent = e;

                                       if (e.EventName == EventName.ChannelAnswer)
                                       {
                                           Log.Info(() => "Channel [{0}] Answered".Fmt(UUID));
                                       }

                                       if (e.EventName == EventName.ChannelHangup)
                                       {
                                           Log.Info(() => "Channel [{0}] Hangup Detected [{1}]".Fmt(UUID, e.HangupCause));
                                           HangupCallBack(e);
                                       }
                                   }));
        }
コード例 #2
0
 protected internal ConferenceEvent(EventMessage other) : base(other)
 {
     if (other.EventName != EventName.Custom && other.Headers[HeaderNames.EventSubclass] != "conference::maintenance")
     {
         throw new InvalidOperationException(
             "Expected event of type Custom with SubClass conference::maintainance, got {0} instead".Fmt(other.EventName));
     }
 }
コード例 #3
0
        /// <summary>
        /// Sends the connect command to FreeSwitch, populating the <see cref="ChannelData"/> property on reply.
        /// </summary>
        public async Task<EventMessage> Connect()
        {
            var response = await SendCommand("connect");
            ChannelData = new EventMessage(response);

            Messages.FirstAsync(m => m.ContentType == ContentTypes.DisconnectNotice)
                            .Subscribe(dn => Log.Trace(() => "Channel {0} Disconnect Notice {1} received.".Fmt(ChannelData.UUID, dn.BodyText)));

            return ChannelData;
        }
コード例 #4
0
 /// <summary>
 /// Sends the connect command to FreeSwitch, populating the <see cref="ChannelData"/> property on reply.
 /// </summary>
 public Task<EventMessage> Connect()
 {
     return SendCommand("connect").ToObservable().Select(reply => new EventMessage(reply)).Do(
         x =>
             {
                 ChannelData = x;
                 Messages.FirstAsync(m => m.ContentType == ContentTypes.DisconnectNotice)
                     .Do(dn => Log.Trace(() => "Channel {0} Disconnect Notice {1} received.".Fmt(ChannelData.UUID, dn.BodyText)));
             }).ToTask();
 }
コード例 #5
0
ファイル: PlayResult.cs プロジェクト: bushadam/NEventSocket
 internal PlayResult(EventMessage eventMessage) : base(eventMessage)
 {
     if (eventMessage != null)
     {
         Success = ResponseText == "FILE PLAYED";  //eventMessage.Headers[HeaderNames.ApplicationResponse] == "FILE PLAYED";
     }
     else
     {
         Success = false;
     }
 }
コード例 #6
0
ファイル: ReadResult.cs プロジェクト: bushadam/NEventSocket
        internal ReadResult(EventMessage eventMessage, string channelVariable) : base(eventMessage)
        {
            if (eventMessage != null)
            {
                Digits = eventMessage.GetVariable(channelVariable);
                var readResult = eventMessage.GetVariable("read_result");
                Result = !string.IsNullOrEmpty(readResult)
                                  ? (ReadResultStatus)Enum.Parse(typeof(ReadResultStatus), readResult, true)
                                  : ReadResultStatus.Failure;
            }
            else
            {
                Result = ReadResultStatus.Failure;
            }

            Success = Result == ReadResultStatus.Success;
        }
コード例 #7
0
ファイル: Channel.cs プロジェクト: bushadam/NEventSocket
        protected Channel(EventMessage eventMessage, EventSocket eventSocket) : base(eventMessage, eventSocket)
        {
            //populate empty bridge status
            Bridge = new BridgeStatus(false, null);
            ExitOnHangup = true;

            Task.WhenAll(
                new[]
                    {
                        eventSocket.SubscribeEvents(), //subscribe to minimum events
                        eventSocket.Filter(HeaderNames.UniqueId, UUID), //filter for our unique id (in case using full socket mode)
                        eventSocket.Filter(HeaderNames.OtherLegUniqueId, UUID) //filter for channels bridging to our unique id
                    }).ContinueWith(
                        t =>
                            {
                                if (t.IsFaulted && t.Exception != null)
                                {
                                    Log.ErrorException("Channel [{0}] - failed to configure outbound socket for Channel usage".Fmt(UUID), t.Exception.InnerException);
                                    return;
                                }

                                this.InitializeSubscriptions();
                            });
        }
コード例 #8
0
 protected internal BridgedChannel(EventMessage eventMessage, EventSocket eventSocket) : base(eventMessage, eventSocket)
 {
 }
コード例 #9
0
 internal BackgroundJobResult(EventMessage basicMessage)
 {
     Headers = basicMessage.Headers;
     BodyText = basicMessage.BodyText;
 }
コード例 #10
0
 private OriginateResult(EventMessage channelEvent)
 {
     ChannelData = channelEvent;
     Success = channelEvent.AnswerState != AnswerState.Hangup;
     HangupCause = channelEvent.HangupCause;
 }
コード例 #11
0
        protected internal AttendedTransferResult(EventMessage eventMessage) : base(eventMessage)
        {
            if (eventMessage == null)
            {
                Status = AttendedTransferResultStatus.Failed;
                return;
            }

            var lastBridgeHangupCause = eventMessage.GetVariable("last_bridge_hangup_cause").HeaderToEnumOrNull<HangupCause>();
            var originateDisposition = eventMessage.GetVariable("originate_disposition").HeaderToEnumOrNull<HangupCause>();
            var xferResult = eventMessage.GetVariable("att_xfer_result");
            var xferUuids = eventMessage.GetVariable("xfer_uuids");
            
            //sometimes xferResult is populated, sometimes it isn't!
            if (xferResult != null && xferResult == "success")
            {
                if (eventMessage.AnswerState == AnswerState.Answered)
                {
                    //b-leg is still connected, let's see if we're in a three-way
                    if (xferUuids != null)
                    {
                        Status = AttendedTransferResultStatus.Threeway;
                        HangupCause = HangupCause.Success;
                    }
                    else if (lastBridgeHangupCause == HangupCause.NormalClearing)
                    {
                        //the c-leg hung up, b-leg is still bridged to a-leg
                        Status = AttendedTransferResultStatus.Failed;
                        HangupCause = HangupCause.CallRejected;
                    }
                }
                else
                {
                    //b-leg is no longer connected, let's assume success
                    Status = AttendedTransferResultStatus.Transferred;
                    HangupCause = HangupCause.Success;
                }
            }
            else if (originateDisposition != null)
            {
                //xferResult wasn't populated, here be dragons..
                //let's try to figure out what happened
                HangupCause = originateDisposition.Value;

                if (HangupCause == HangupCause.Success) 
                {
                    if (eventMessage.AnswerState == AnswerState.Hangup)
                    {
                        //b-leg has hungup, we've transferred to the c-leg
                        Status = AttendedTransferResultStatus.Transferred;
                    }
                    else
                    {
                        //b-leg is still connected
                        Status = AttendedTransferResultStatus.Failed;
                        HangupCause = HangupCause.CallRejected;
                    }
                }
                else if (HangupCause == HangupCause.AttendedTransfer)
                {
                    //we'll get here if the b-leg hung up while the c-leg was ringing
                    //in this case, FreeSwitch will keep ringing the c-leg
                    //if the c-leg answers, a-leg will be bridged to the c-leg
                    //if the c-leg does not answer, then FreeSwitch will attempt to ring
                    //back the b-leg and bridge the a-leg to the b-leg WITH A NEW CHANNEL.
                    Status = AttendedTransferResultStatus.AttendedTransfer;
                }
            }
        }
コード例 #12
0
        public void it_should_parse_event_messages(string input, EventName eventName)
        {
            var parser = new Parser();
            var rawInput = input.Replace("\r\n", "\n") + "\n\n";
            foreach (char c in rawInput)
            {
                parser.Append(c);
            }

            Assert.True(parser.Completed);

            var eventMessage = new EventMessage(parser.ExtractMessage());
            Assert.NotNull(eventMessage);
            Assert.Equal(eventName, eventMessage.EventName);

            Console.WriteLine(eventMessage.ToString());
        }