C# VoiceCall API
Collaboration diagram for C# VoiceCall API:

Modules

 Enumerations
 
 Events related with Voice Call Service
 

Classes

interface  ICall
 Interface defining a Call More...
 
interface  IVoiceCallManager
 The VoiceCall class that should be used to interact with the installed More...
 
interface  IVoiceCallSource
 Voice Call source More...
 

Detailed Description

To work with Deepsy Voice Call Manager service it is necessary to use VoiceCallManager located in GMV.ITS.HAL.DEEPSY.VoiceCall.Facade for getting the initial VoiceCallManager object.

VoiceCallManager voiceCallManager = new VoiceCallManager("");


VoiceCallManager has an optional parameter indicating the ip address of remote service. For instance:

VoiceCallManager voiceCallManager = new VoiceCallManager("172.22.198.103");


VoiceCallManager implements IDisposable. It can hold resources (such as socket handles) until it is disposed. The Dispose method is automatically called when existing a using or try / catch block, for which the object has been declared. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur.

  • * VoiceCallManager voiceCallManager = null;
    try{
    voiceCallManager = new VoiceCallManager(("172.22.198.103");
    List<IVoiceCallSource> sources = voiceCallManager.GetVoiceCallSources().ToList();
    } catch (Exception e) {
    throw e;
    }
    voiceCallManager?.Dispose();

Examples

  • Get a list of available sources
    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.VoiceCall
    {
    public class ListCallsFromSourcesApp
    {
    public static int Main(string[] args)
    {
    try
    {
    VoiceCallManager voiceCallManager = new VoiceCallManager("192.168.0.123");
    List<IVoiceCallSource> sources = voiceCallManager.GetVoiceCallSources().ToList();
    foreach (IVoiceCallSource source in sources)
    {
    Console.WriteLine("Source detected");
    List<ICall> callList = source.GetCalls().ToList();
    Console.WriteLine("Listing calls for source: ");
    foreach (ICall call in callList)
    {
    try
    {
    Console.WriteLine("");
    ICallInformation callinfo = call.GetCallInformation();
    Console.WriteLine($"\t LocalSourceId \t| {callinfo.LocalSourceId}");
    Console.WriteLine($"\t RemoteSourceId \t| {callinfo.RemoteSourceId}");
    Console.WriteLine($"\t CallDirection \t| {callinfo.CallDirection}");
    Console.WriteLine($"\t CallStatus \t| {callinfo.CallStatus}");
    Console.WriteLine($"\t CallType \t| {callinfo.CallType}");
    Console.WriteLine($"\t CreationDate \t| {callinfo.CreationDate}");
    Console.WriteLine($"\t DurationSeconds\t| {callinfo.DurationSeconds}");
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception e)
    {
    Console.WriteLine($"Error in call information: {e.Message}");
    }
    }
    }
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Exception exception {ex.Message}");
    }
    return -1;
    }
    }
    }

  • Make a call
    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.VoiceCall
    {
    public class MakeAcallApp
    {
    public static int Main(string[] args)
    {
    int MaxAllowedCallDuration = 30;
    try
    {
    VoiceCallManager voiceCallManager = new VoiceCallManager("192.168.0.123");
    List<IVoiceCallSource> sources = voiceCallManager.GetVoiceCallSources().ToList();
    if (sources.Any())
    {
    IVoiceCallSource source = sources.FirstOrDefault();
    Console.WriteLine("Performing call with first source in voice call list");
    ICall myCall = null;
    // Depending on the source, we will configure it and make a call according to its type
    if(source.Id == "baresip")
    {
    myCall = MakeVoipCallFromSource(source);
    }
    else
    {
    myCall = MakePhoneCallFromSource(source);
    }
    myCall.CallStatus += MyCall_CallStatus;
    ICallInformation callinfo = myCall.GetCallInformation();
    Console.WriteLine($"\t LocalSourceId \t| {callinfo.LocalSourceId}");
    Console.WriteLine($"\t RemoteSourceId \t| {callinfo.RemoteSourceId}");
    Console.WriteLine($"\t CallDirection \t| {callinfo.CallDirection}");
    Console.WriteLine($"\t CallStatus \t| {callinfo.CallStatus}");
    Console.WriteLine($"\t CallType \t| {callinfo.CallType}");
    Console.WriteLine($"\t CreationDate \t| {callinfo.CreationDate}");
    Console.WriteLine($"\t DurationSeconds\t| {callinfo.DurationSeconds}");
    DateTime now = DateTime.UtcNow;
    Console.Write($"Call will be finished after {MaxAllowedCallDuration} seconds or press <Enter> to finish it");
    ConsoleKey key = ConsoleKey.Escape;
    while ((DateTime.UtcNow - now).TotalSeconds < MaxAllowedCallDuration
    && key != ConsoleKey.Enter)
    {
    if (Console.KeyAvailable)
    {
    key = Console.ReadKey().Key;
    }
    }
    if (myCall.GetCallInformation().CallStatus != CallStatus.Status.FINISHED)
    {
    Console.Write($"Finishing call with {myCall.GetCallInformation().RemoteSourceId} after {MaxAllowedCallDuration} seconds");
    myCall.FinishCall();
    }
    }
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Exception exception {ex.Message}");
    }
    return -1;
    }
    private static ICall MakeVoipCallFromSource(IVoiceCallSource source)
    {
    // We need to configure source settings for connecting.
    // This may be only neceessary the first time
    source.SetConfiguration(new VoiceCallConfiguration() { Parameter = CallParameter.Parameter.SIP_ACCOUNT, Value = "<sip:root@localhost>;regint=0;" }) ;
    source.SetConfiguration(new VoiceCallConfiguration() { Parameter = CallParameter.Parameter.SIP_LOCAL_PORT, Value = "5001" });
    source.SetConfiguration(new VoiceCallConfiguration() { Parameter = CallParameter.Parameter.RTP_LOCAL_PORT_RANGE, Value = "10000-10010" });
    source.SetConfiguration(new VoiceCallConfiguration() { Parameter = CallParameter.Parameter.SIP_CODECS, Value = "G711,OPUS" });
    return source.MakeCall("user@127.0.0.1");
    }
    private static ICall MakePhoneCallFromSource(IVoiceCallSource source)
    {
    return source.MakeCall("600123456");
    }
    private static void MyCall_CallStatus(object sender, ICallStatusEvent e)
    {
    Console.Write($"Call with {e.Call.GetCallInformation().LocalSourceId} new status is {e.Status}");
    Console.Write($"Call duration is {e.Call.GetCallInformation().DurationSeconds}");
    }
    }
    }

  • Get Call configuration
    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.VoiceCall
    {
    public class RetrieveCallConfParamsApp
    {
    public static int Main(string[] args)
    {
    try
    {
    VoiceCallManager voiceCallManager = new VoiceCallManager("192.168.0.123");
    List<IVoiceCallSource> sources = voiceCallManager.GetVoiceCallSources().ToList();
    IVoiceCallSource source = sources.FirstOrDefault();
    if (sources != null)
    {
    List<CallParameter.Parameter> parameterList = new List<CallParameter.Parameter>();
    parameterList.Add(CallParameter.Parameter.NUM_OF_RINGS);
    parameterList.Add(CallParameter.Parameter.AUTOMATIC_ANSWER);
    parameterList.Add(CallParameter.Parameter.AUDIO_MODE);
    parameterList.Add(CallParameter.Parameter.RINGTONE);
    List<IVoiceCallConfiguration> configList = source.GetCallConfiguration(parameterList).ToList();
    Console.WriteLine("Retrieving configuration list for first source in list, source id :");
    foreach (IVoiceCallConfiguration parameter in configList)
    {
    Console.WriteLine($"Parameter [{parameter.Parameter}] value {parameter.Value}");
    }
    }
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Exception exception {ex.Message}");
    }
    return -1;
    }
    }
    }

  • Voice Call Events
    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.VoiceCall
    {
    public class VoicecallEventsApp
    {
    public static int Main(string[] args)
    {
    try
    {
    VoiceCallManager voiceCallManager = new VoiceCallManager("192.168.0.123");
    voiceCallManager.SourceListEvent += VoiceCallManager_SourceListEvent;
    List<IVoiceCallSource> sources = voiceCallManager.GetVoiceCallSources().ToList();
    foreach(IVoiceCallSource source in sources)
    {
    source.NewCallEvent += Source_NewCallEvent;
    source.SourceStatusEvent += Source_SourceStatusEvent;
    List<ICall> calls = source.GetCalls().ToList();
    foreach(ICall call in calls)
    {
    call.CallStatus += Call_CallStatus;
    }
    }
    Console.Write($"Press <Enter> for exit");
    ConsoleKey key = ConsoleKey.Escape;
    while (key != ConsoleKey.Enter)
    {
    if (Console.KeyAvailable)
    {
    key = Console.ReadKey().Key;
    }
    }
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Exception exception {ex.Message}");
    }
    return -1;
    }
    private static void Call_CallStatus(object sender, ICallStatusEvent e)
    {
    Console.Write($"App::CallStatusEvent");
    Console.Write($"Call with {e.Call.GetCallInformation().LocalSourceId} new status is {e.Status}");
    Console.Write($"Call duration is {e.Call.GetCallInformation().DurationSeconds}");
    }
    private static void Source_SourceStatusEvent(object sender, IVoiceCallSourceStatusEvent e)
    {
    Console.Write($"App::SourceStatusEvent");
    Console.Write($"Source {e.Source.Id} new status is {e.Status}");
    }
    private static void Source_NewCallEvent(object sender, INewCallEvent e)
    {
    Console.Write("App::NewCallEvent");
    Console.Write($"Call Source {e.Call.Id}");
    e.Call.CallStatus += Call_CallStatus;
    }
    private static void VoiceCallManager_SourceListEvent(object sender, IVoiceCallSourceListEvent e)
    {
    Console.Write("App::VoiceCallSourceListEvent");
    if(e.Action == DEEPSY.VoiceCall.Interface.Enum.VoiceCallListAction.Action.ADDED)
    {
    Console.WriteLine($"Added {e.VoiceCallSource.Id}");
    e.VoiceCallSource.NewCallEvent += Source_NewCallEvent;
    List<ICall> calls = e.VoiceCallSource.GetCalls().ToList();
    foreach (ICall call in calls)
    {
    call.CallStatus += Call_CallStatus;
    }
    e.VoiceCallSource.SourceStatusEvent += Source_SourceStatusEvent;
    }
    else
    {
    Console.WriteLine($"Removed {e.VoiceCallSource.Id}");
    }
    }
    }
    }

  • Audio Task Operations
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    namespace GMV.ITS.HAL.Deepsy.Examples.Audio
    {
    class PlayTrackExample
    {
    static void Main(string[] args)
    {
    try
    {
    string deepsyServerIp = args.Length == 0 ? "192.168.0.144" : args[0];
    using (AudioManager audioManager = new AudioManager(deepsyServerIp))
    {
    audioManager.PortListEvent += AudioManager_PortListEvent;
    audioManager.ConnectionListEvent += AudioManager_ConnectionListEvent;
    IAudioPort myPort = audioManager.CreatePort("user_port", AudioPortType.Type.OUTPUT);
    List<IAudioPort> ports = audioManager.GetPorts().ToList();
    IAudioPort destination = ports.FirstOrDefault(port => port.Type == AudioPortType.Type.INPUT && port.Client.Contains("external_speaker_r"));
    if (destination == null)
    {
    Console.WriteLine("Port not found");
    return;
    }
    Console.WriteLine($"Port {destination.Client}:{destination.Name}.Type {destination.Type}");
    IAudioConnection myConnection = audioManager.CreateConnection("my_connection", myPort, destination);
    List<IAudioConfiguration> configurations = new List<IAudioConfiguration>();
    configurations.Add(new DEEPSY.Audio.Dto.AudioConfiguration()
    {
    Value = 80,
    Configuration = AudioConfiguration.Configuration.VOLUME
    });
    IAudioTask track = audioManager.Play(myPort, "/usr/bin/test/stereoTest.wav", configurations );
    track.TaskStatusEvent += Track_TaskStatusEvent;
    Thread.Sleep(2000);
    Console.WriteLine($"track status: {track.GetStatus()}");
    Thread.Sleep(2000);
    Console.WriteLine($"track status: {track.GetStatus()}");
    Thread.Sleep(2000);
    Console.WriteLine($"track status: {track.GetStatus()}");
    Thread.Sleep(2000);
    Console.WriteLine($"track status: {track.GetStatus()}");
    Console.WriteLine("Press any key for exit");
    Console.ReadKey();
    myConnection.RemoveConnection();
    audioManager.RemovePort(myPort);
    }
    }
    catch (HalException deepsyEx)
    {
    Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");
    }
    catch (Exception ex)
    {
    Console.WriteLine($"Error Not Handled exception {ex.Message}");
    }
    }
    private static void AudioManager_ConnectionListEvent(object sender, IAudioConnectionListEvent e)
    {
    if (e.Type == AudioListEventType.Type.ADDED)
    {
    Console.WriteLine($"ADDED Audio Connection with id {e.Connection.Id}");
    }
    else
    {
    Console.WriteLine($"REMOVED Audio Connection with id {e.Connection.Id}");
    }
    }
    private static void AudioManager_PortListEvent(object sender, IAudioPortListEvent e)
    {
    if (e.Type == AudioListEventType.Type.ADDED)
    {
    Console.WriteLine($"ADDED Audio Port {e.Port.Client}:{e.Port.Name}");
    }
    else
    {
    Console.WriteLine($"REMOVED Audio Port with id {e.Port.Client}:{e.Port.Name}");
    }
    }
    private static void Track_TaskStatusEvent(object sender, IAudioTaskStatusEvent e)
    {
    Console.WriteLine($"Task {e.TaskId}, Status {e.Status}");
    }
    }
    }