Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Data.SqlClient;
- using System.Collections.Generic;
- using FreeSWITCH.Native;
- namespace FreeSWITCH.Managed.DialOut
- {
- public class DialOut : IAppPlugin
- {
- public FreeSWITCH.Native.Api fsApi;
- public void Run(AppContext context)
- // ***************************************************************************************************
- {
- fsApi = new FreeSWITCH.Native.Api();
- context.Session.HangupFunction = () => HandleHangup(context.Session);
- simpleCall(context.Session, "316*********@*.*.*.*", "3134*******", 30);
- if (context.Session.Ready())
- {
- Debug("A-Leg was still here, so hanging up...");
- context.Session.Hangup("NORMAL_CLEARING");
- }
- Debug("End of run...");
- }
- private string simpleCall(ManagedSession leg_a, string route, string orig, int timeout)
- {
- Debug("SimpleCall()");
- string obCause = "ERROR";
- Debug("Creating the new session...");
- ManagedSession leg_b = new ManagedSession("{ignore_early_media=true,origination_caller_id_number=" + orig + ",originate_timeout=20}sofia/external/" + route);
- if (leg_b.Ready())
- {
- if (leg_b.answered())
- {
- leg_a.Answer();
- leg_a.sleep(1000, 0);
- string apiResult = fsApi.ExecuteString(string.Format("uuid_bridge {1} {0}", leg_a.GetUuid(), leg_b.GetUuid()));
- Debug("apiResult=" + apiResult);
- obCause = "SUCCESS";
- Debug("As long as both legs are Ready(), we wait......");
- while (leg_a.bridged() && leg_b.bridged())
- {
- leg_a.sleep(1000, 0); // Slow it down...
- }
- Debug("There is one leg no longer ready...");
- if (leg_a.bridged()) { Debug("Session A still ready..."); } else { Debug("Session A NO LONGER ready..."); }
- if (leg_b.bridged()) { Debug("Session B still ready..."); } else { Debug("Session B NO LONGER ready..."); }
- }
- else
- {
- Debug("A-Leg aborted while dialing...");
- }
- if (leg_b.Ready())
- {
- Debug("B-Leg still here, so hanging up B-Leg...");
- leg_b.Hangup("NORMAL_CALL_CLEARING");
- leg_b.destroy();
- }
- }
- else
- {
- obCause = leg_b.hangupCause();
- }
- Debug("SimpleCall() ended with: " + obCause);
- return obCause;
- }
- private string simpleCall2(ManagedSession leg_a, string route, string orig, int timeout)
- {
- Debug("SimpleCall2()");
- leg_a.Execute("bridge", "{ignore_early_media=true,origination_caller_id_number=" + orig + ",originate_timeout=20}sofia/external/" + route);
- return "";
- }
- private string simpleCall3(ManagedSession leg_a, string route, string orig, int timeout)
- {
- Debug("SimpleCall3()");
- string Uuid_b = fsApi.ExecuteString("create_uuid");
- Debug(fsApi.ExecuteString("originate {ignore_early_media=true,origination_uuid=" + Uuid_b + ",origination_caller_id_number=" + orig + ",originate_timeout=20}sofia/external/" + route + " &managed(fsMCXessOutbound)"));
- Debug("Answered, will now bridge...");
- Debug(fsApi.ExecuteString(string.Format("uuid_bridge {1} {0}", leg_a.GetUuid(), Uuid_b)));
- while (leg_a.bridged()) { }
- Debug("No longer bridged so exiting...");
- return "";
- }
- private void HandleHangup(ManagedSession session)
- {
- Debug("HandleHangUp();");
- Debug("Finalizing call in CDR table");
- // a_leg should always come here at the end of it's call
- }
- private void Debug(string Message)
- {
- Log.WriteLine(LogLevel.Error, "=============> " + Message);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement