Esempio n. 1
0
        public virtual string SetVar(string var, string value, string uuid = "")
        {
            /*
             * Please refer to http;//wiki.freeswitch.org/wiki/Mod_commands#uuid_setvar
             *
             * For Inbound connection, uuid argument is mandatory.
             * """ */
            string result;

            if (string.IsNullOrEmpty(value))
            {
                value = "";
            }
            if (string.IsNullOrEmpty(uuid))
            {
                //uuid = get_channel_unique_id();
            }

            Event api_response = APICommand(String.Format("uuid_setvar {0} {1} {2}", uuid, var, value));

            result = api_response.GetBody().Trim();
            if (string.IsNullOrEmpty(result))
            {
                result = "";
            }
            return(result);
        }
Esempio n. 2
0
        public virtual string GetVar(string var, string uuid = "")
        {
            /*
             * Please refer to http;//wiki.freeswitch.org/wiki/Mod_commands#uuid_getvar
             * For Inbound and Outbound connection, uuid argument is mandatory.
             */

            string result;

            Event api_response = APICommand(String.Format("uuid_getvar {0} {1}", var, uuid));

            result = api_response.GetBody().Trim();
            if (result == "_unpublic Event_")
            {
                result = "";
            }
            return(result);
        }
Esempio n. 3
0
        public void ON_BACKGROUND_JOB(Event ev)
        {
            Request call_req = new Request(null, null, null, null, null);

            string status = string.Empty;
            string reason = string.Empty;
            //Capture Job Event
            // Capture background job only for originate and ignore all other jobs
            string job_cmd = ev.GetHeader("Job-Command");
            string job_uuid = ev.GetHeader("Job-UUID");
            if (job_cmd == "originate" && string.IsNullOrEmpty(job_uuid))
            {
                try
                {
                    string data = ev.GetBody();
                    int pos = data.IndexOf(' ');
                    if (pos != -1)
                    {
                        status = data.Substring(0, pos).Trim();
                        reason = data.Substring(pos + 1).Trim();
                    }
                }
                catch (Exception ex)
                {
                    return;
                }
                string CallSid = BackgroundJobs[job_uuid];
                if (string.IsNullOrEmpty(CallSid))
                {
                    return;
                }
                try
                {
                    call_req = CallRequest[CallSid];
                }
                catch (Exception ex)
                {
                    return;
                }
                //Handle failure case of originate
                //This case does not raise a on_channel_hangup event.
                //All other failures will be captured by on_channel_hangup
                if (!status.Contains("OK"))
                    //In case ring/early state done, just warn releasing call request will be done in hangup event
                    if (call_req.state_flag == "Ringing" || call_req.state_flag == "EarlyMedia")
                    {
                        return;
                    }
                    //If no more gateways, release call request
                    else if (call_req.gateways.Count == 0)
                    {
                        //set an empty call_uuid
                        string call_uuid = "";
                        string hangup_url = call_req.hangup_url;
                        SetHangUpComplete(CallSid, call_uuid, reason, ev, hangup_url);
                        return;
                    }
                    //If there are gateways and call request state_flag is not set
                    //try again a call
                    else if (call_req.gateways.Count > 0)
                        Originate(CallSid);

            }
        }