コード例 #1
0
ファイル: FSInbound.cs プロジェクト: lichien2017/AgbaraVOIP
        public void ON_SESSION_HEARTBEAT(Event ev)
        {
            //TODO
            //store in db

            long answer_seconds_since_epoch    = long.Parse(ev.GetHeader("Caller-Channel-Answered-Time"));
            long heartbeat_seconds_since_epoch = long.Parse(ev.GetHeader("Event-Date-Timestamp"));
            int  ElapsedTime = EpochTimeConverter.GetEpochTimeDifferent(heartbeat_seconds_since_epoch, answer_seconds_since_epoch);
            var  BCallSid    = ev.GetHeader("variable_agbara_bleg_callsid");
            var  ACallSid    = ev.GetHeader("variable_agbara_callsid");

            if (!string.IsNullOrEmpty(BCallSid))
            {
                int current = CallElapsedTime[BCallSid];
                CallElapsedTime[BCallSid] = current + ElapsedTime;
            }
            else if (!string.IsNullOrEmpty(ACallSid))
            {
                int current = CallElapsedTime[ACallSid];
                CallElapsedTime[ACallSid] = current + ElapsedTime;
            }

            //TODO
            //bill user real time here
        }
コード例 #2
0
ファイル: FSInbound.cs プロジェクト: lichien2017/AgbaraVOIP
        private void SetHangUpComplete(string CallSid, string call_uuid, string reason, Event ev, string hangup_url)
        {
            long   answer_seconds_since_epoch = long.Parse(ev.GetHeader("Caller-Channel-Answered-Time"));
            long   hangup_seconds_since_epoch = long.Parse(ev.GetHeader("Caller-Channel-Hangup-Time"));
            string called_num = ev.GetHeader("Caller-Destination-Number");
            string caller_num = ev.GetHeader("Caller-Caller-ID-Number");
            string direction  = ev.GetHeader("variable_agbara_call_direction");
            //get call details
            Call call = callSrvc.GetCallDetail(CallSid);

            call.Status      = CallStatus.completed;
            call.CallerId    = caller_num;
            call.CallTo      = called_num;
            call.DateUpdated = DateTime.Now;
            call.StartTime   = EpochTimeConverter.ConvertFromEpochTime(answer_seconds_since_epoch);
            call.EndTime     = EpochTimeConverter.ConvertFromEpochTime(hangup_seconds_since_epoch);
            call.Duration    = EpochTimeConverter.GetEpochTimeDifferent(hangup_seconds_since_epoch, answer_seconds_since_epoch);
            call.Direction   = direction;

            try
            {
                CallRequest.Remove(CallSid);
                CallElapsedTime.Remove(CallSid);
            }
            catch (Exception ex)
            {
            }

            try
            {
                callSrvc.UpdateCallLog(call);
            }
            catch (Exception ex)
            {
            }
        }
コード例 #3
0
        public override void Execute(FSOutbound outboundClient)
        {
            List <string> numbers         = new List <string>();
            string        sched_hangup_id = string.Empty;
            string        dialNumber      = string.Empty;

            if (!string.IsNullOrEmpty(base.Text.Trim()))
            {
                dialNumber = base.Text.Trim();
                Number num = new Number();
                num.number = dialNumber;
                numbers.Add(PrepareNumber(num, outboundClient));
            }
            else
            {
                //Set numbers to dial from Number nouns
                foreach (Element child in Children)
                {
                    string     dial_num = "";
                    Number     num      = null;
                    Conference conf     = null;
                    if (child.GetType() == typeof(Number))
                    {
                        num      = (Number)child;
                        dial_num = PrepareNumber(num, outboundClient);
                        if (string.IsNullOrEmpty(dial_num))
                        {
                            continue;
                        }
                        numbers.Add(dial_num);
                    }
                    else if (child.GetType() == typeof(Conference))
                    {
                        //if conference is needed
                        conf = (Conference)child;
                        //set record for conference
                        if (record)
                        {
                            conf.record = true;
                        }
                        //set hangupOnStar for member
                        if (hangupOnStar)
                        {
                            conf.hangup_on_star = true;
                        }
                        //Create Partcipant
                        Participant participant = new Participant();
                        participant.CallSid    = outboundClient.CallSid;
                        participant.AccountSid = outboundClient.AccountSid;
                        conf.participant       = participant;
                        conf.Execute(outboundClient);
                    }
                }
            }
            if (numbers == null)
            {
                return;
            }
            else
            {
                string duration_ms = string.Empty;
                Call   bleg        = new Call();
                //Set timeout
                outboundClient.set(string.Format("call_timeout={0}", timeout));
                outboundClient.set(string.Format("answer_timeout={0}", timeout));
                //Set callerid or unset if not provided
                if (!string.IsNullOrEmpty(caller_id))
                {
                    outboundClient.set(string.Format("effective_caller_id_number={0}", caller_id));
                }
                else
                {
                    outboundClient.unset("effective_caller_id_number");
                }
                //Set continue on fail
                outboundClient.set("continue_on_fail=true");
                //Set ring flag if dial will ring.
                //But first set agbara_dial_rang to false to be sure we don't get it from an old Dial
                outboundClient.set("agbara_dial_rang=false");
                outboundClient.set("execute_on_ring=set::agbara_dial_rang=true");

                //Create dialstring
                dial_str = string.Join(":_:", numbers);

                // Don't hangup after bridge !
                outboundClient.set("hangup_after_bridge=false");
                if (hangupOnStar)
                {
                    outboundClient.set("bridge_terminate_key=*");
                }
                else
                {
                    outboundClient.unset("bridge_terminate_key");
                }
                outboundClient.set("bridge_early_media=true");
                outboundClient.unset("instant_ringback");
                outboundClient.unset("ringback");

                //set bleg call sid
                outboundClient.set(string.Format("agbara_bleg_callsid={0}", bleg.Sid));
                //enable session heartbeat
                outboundClient.set("enable_heartbeat_events=60");

                // set call direction
                outboundClient.set(string.Format("agbara_call_direction={0}", CallDirection.outbounddial));
                string dial_rang    = "";
                string hangup_cause = "NORMAL_CLEARING";

                //string recordingPath = "";
                //AppSettingsReader reader = new AppSettingsReader();
                //recordingPath = (string)reader.GetValue("RecordingDirectory", recordingPath.GetType());
                //var CallSid = outboundClient.CallSid;
                //string filename = string.Format("{0}_{1}", DateTime.UtcNow.ToShortDateString(), outboundClient.get_channel_unique_id());
                //string record_file = string.Format("{0}{1}.wav", recordingPath, CallSid);
                //if (record)
                //{
                //    outboundClient.set("RECORD_STEREO=true");
                //    outboundClient.APICommand(string.Format("uuid_record {0} start {1}", outboundClient.get_channel_unique_id(), record_file));
                //}


                try
                {
                    //execute bridge
                    outboundClient.bridge(dial_str, outboundClient.get_channel_unique_id(), true);
                    //waiting event
                    var evnt = outboundClient.ActionReturnedEvent();
                    //parse received events
                    if (evnt.GetHeader("Event-Name") == "CHANNEL_UNBRIDGE")
                    {
                        evnt = outboundClient.ActionReturnedEvent();
                    }
                    string reason = "";
                    string originate_disposition = evnt.GetHeader("variable_originate_disposition");

                    long answer_seconds_since_epoch = long.Parse(evnt.GetHeader("Caller-Channel-Answered-Time"));
                    long end_seconds_since_epoch    = long.Parse(evnt.GetHeader("Event-Date-Timestamp"));

                    hangup_cause = originate_disposition;
                    if (hangup_cause == "ORIGINATOR_CANCEL")
                    {
                        reason = string.Format("{0} (A leg)", hangup_cause);
                    }
                    else
                    {
                        reason = string.Format("{0} (B leg)", hangup_cause);
                    }
                    if (string.IsNullOrEmpty(hangup_cause) || hangup_cause == "SUCCESS")
                    {
                        hangup_cause = outboundClient.GetHangupCause();
                        reason       = string.Format("{0} (A leg)", hangup_cause);
                        if (string.IsNullOrEmpty(hangup_cause))
                        {
                            hangup_cause = outboundClient.GetVar("bridge_hangup_cause", outboundClient.get_channel_unique_id());
                            reason       = string.Format("{0} (B leg)", hangup_cause);
                            if (string.IsNullOrEmpty(hangup_cause))
                            {
                                hangup_cause = outboundClient.GetVar("hangup_cause", outboundClient.get_channel_unique_id());
                                reason       = string.Format("{0} (A leg)", hangup_cause);
                                if (string.IsNullOrEmpty(hangup_cause))
                                {
                                    hangup_cause = "NORMAL_CLEARING";
                                    reason       = string.Format("{0} (A leg)", hangup_cause);
                                }
                            }
                        }
                    }

                    //Get ring status
                    dial_rang = outboundClient.GetVar("agbara_dial_rang", outboundClient.get_channel_unique_id());

                    //get duration
                    duration_ms = EpochTimeConverter.GetEpochTimeDifferent(answer_seconds_since_epoch, end_seconds_since_epoch).ToString();
                }

                catch (Exception e)
                {
                }
                finally
                {
                    outboundClient.session_params.Add("DialCallSid", bleg.Sid);
                    outboundClient.session_params.Add("DialCallDuration", duration_ms);
                    if (dial_rang == "true")
                    {
                        outboundClient.session_params.Add("DialCallStatus", CallStatus.completed);
                    }
                    else
                    {
                        outboundClient.session_params.Add("DialCallStatus", CallStatus.failed);
                    }
                }
            }

            //If record is specified
            if (record)
            {
                outboundClient.session_params.Add("RecordingUrl", "");
            }

            if (!string.IsNullOrEmpty(action) && Util.IsValidUrl(action) && !string.IsNullOrEmpty(method))
            {
                Task.Factory.StartNew(() => FetchNextAgbaraRespone(action, outboundClient.session_params, method));
            }
        }