Package com.gmv.its.deepsy.hal.voicecall

Classes

interface  Call
 Class defining a Call. More...
 
interface  CallInformation
 Call information. More...
 
interface  CallObserver
 Call observer. More...
 
enum  CallStatus
 
interface  CallStatusEvent
 Call event. More...
 
interface  NewCallEvent
 New Call Event. More...
 
enum  SourceStatus
 
class  VoiceCallConfiguration
 Voice Call Configuration class. More...
 
class  VoiceCallLowLevelException
 VoiceCall low level exception. More...
 
interface  VoiceCallManager
 VoiceCall Manager. More...
 
class  VoiceCallNotAvailableException
 VoiceCall not available exception. More...
 
interface  VoiceCallSource
 
interface  VoiceCallSourceEvent
 Voice Call Source event. More...
 
interface  VoiceCallSourceListEvent
 Voice Call Source list Event. More...
 
interface  VoiceCallSourceListObserver
 
interface  VoiceCallSourceObserver
 
interface  VoiceCallSourceStatusEvent
 Voice Call Source status event. This event is thrown when a voice call source changes its status. More...
 

Detailed Description

To work with Deepsy voice call service it is necessary to use DeepsyVoiceCallManager located in com.gmv.its.deepsy.hal.voicecall for getting the initial VoiceCallManager object.

VoiceCallManager voiceCallManager = DeepsyVoiceCallManager.getInstance();


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

VoiceCallManager voiceCallManager = DeepsyVoiceCallManager.getInstance("192.168.1.10");


VoiceCallManager is an AutoCloseable interface. An object that may hold resources (such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur. To obtain a list of the voicecall sources objects:

try (VoiceCallManager voiceCallManager = DeepsyVoiceCallManager.getInstance()){
List<VoiceCallSource> sources = voicecallManager.getVoiceCallSources();
} catch (VoiceCallNotAvailableException e) {
e.printStackTrace();
} catch (VoiceCallLowLevelException e) {
e.printStackTrace();
}


If this object is not inside a try with resources block, it is recommended to call to voiceCallManager.close() in order to finalize properly;

voiceCallManager.close();

Service availability

To detect service availability the DeepsyVoiceCallManager implements Manager interface which provides methods for getting availability and subscribing to availability events.

class MyManagerObserver implements ManagerObserver{
public void notify(ManagerConnectionEvent event) {
System.out.println(event.getManager().getName() + " in "+ event.getManager().getIp() + " "+ event.getAction().toString());
}
}
public class App {
public static void main(String[] args) {
ManagerObserver observer = new MyManagerObserver();
try (VoiceCallManager voiceCallManager = DeepsyVoiceCallManager.getInstance()){
voiceCallManager.subscribe(observer);
} catch (CannotSubscribeException e1) {
e1.printStackTrace();
}
}
}


Examples

  • Subscribe to the different events: source list events, source events and call events
    package com.gmv.its.dpyjavaexamples.voicecall;
    import com.gmv.its.deepsy.voicecall.DeepsyVoiceCallManager;
    class MyCallObserver implements CallObserver {
    public void notify(CallStatusEvent event) {
    System.out.println(" App::CallStatusEvent");
    try {
    System.out.println("Call with " + event.getCall().getCallInformation().getRemoteSourceId()
    + " status has changed, new status is " + event.getStatus());
    System.out.println("Call duration is " + event.getCall().getCallInformation().getDurationSeconds());
    } catch (VoiceCallNotAvailableException e) {
    e.printStackTrace();
    } catch (VoiceCallLowLevelException e) {
    e.printStackTrace();
    }
    }
    }
    class MyVoiceCallSourceObserver implements VoiceCallSourceObserver {
    private MyCallObserver callObserver;
    public MyVoiceCallSourceObserver(MyCallObserver myCallObserver) {
    callObserver = myCallObserver;
    }
    public void notify(VoiceCallSourceEvent evt) {
    System.out.println("App::VoiceCallSourceEvent");
    if (evt instanceof NewCallEvent) {
    NewCallEvent event = (NewCallEvent) evt;
    try {
    event.getCall().subscribe(callObserver);
    } catch (CannotSubscribeException e) {
    e.printStackTrace();
    }
    System.out.println(" App::New call");
    } else if (evt instanceof VoiceCallSourceStatusEvent) {
    VoiceCallSourceStatusEvent event = (VoiceCallSourceStatusEvent) evt;
    System.out.println(" App::Source new status: " + event.getSourceStatus());
    }
    }
    }
    class MyVoiceCallSourceListObserver implements VoiceCallSourceListObserver {
    private MyCallObserver callObserver;
    private MyVoiceCallSourceObserver voiceCallSourceObserver;
    public MyVoiceCallSourceListObserver(MyCallObserver myCallObserver,
    MyVoiceCallSourceObserver myVoiceCallSourceObserver) {
    callObserver = myCallObserver;
    voiceCallSourceObserver = myVoiceCallSourceObserver;
    }
    public void notify(VoiceCallSourceListEvent event) {
    System.out.println("App::VoiceCallSourceListEvent");
    if (event.getAction() == VoiceCallSourceListEvent.VoiceCallSourceListAction.ADDED) {
    System.out.println(" App::Voice call source with added");
    try {
    event.getSource().subscribe(voiceCallSourceObserver);
    for (Call call : event.getSource().getCalls()) {
    call.subscribe(callObserver);
    }
    } catch (CannotSubscribeException e) {
    e.printStackTrace();
    }
    }
    }
    }
    public class VoicecallEventsApp {
    public static void main(String[] args) {
    MyCallObserver myCallObserver = new MyCallObserver();
    MyVoiceCallSourceObserver myVoiceCallSourceObserver = new MyVoiceCallSourceObserver(myCallObserver);
    MyVoiceCallSourceListObserver myVoiceCallSourceListObserver = new MyVoiceCallSourceListObserver(myCallObserver,
    myVoiceCallSourceObserver);
    try (VoiceCallManager voicecallManager = DeepsyVoiceCallManager.getInstance("192.168.0.83")) {
    voicecallManager.subscribe(myVoiceCallSourceListObserver);
    for (VoiceCallSource source : voicecallManager.getVoiceCallSources()) {
    System.out.println("App::Source detected");
    source.subscribe(myVoiceCallSourceObserver);
    for (Call call : source.getCalls()) {
    call.subscribe(myCallObserver);
    }
    }
    // Wait for events for 180 seconds
    Thread.sleep(180000);
    } catch (VoiceCallNotAvailableException e) {
    e.printStackTrace();
    } catch (VoiceCallLowLevelException e) {
    e.printStackTrace();
    } catch (CannotSubscribeException e) {
    e.printStackTrace();
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    System.out.println("App::Closing app");
    }
    }

  • List calls from the existing sources
    package com.gmv.its.dpyjavaexamples.voicecall;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import com.gmv.its.deepsy.voicecall.DeepsyVoiceCallManager;
    import java.time.Instant;
    import java.time.ZonedDateTime;
    import java.time.ZoneOffset;
    public class ListCallsFromSourcesApp {
    public static void main(String[] args) {
    System.out.println("Using voice call manager at 192.168.0.86");
    try (VoiceCallManager voicecallManager = DeepsyVoiceCallManager.getInstance("192.168.0.86")) {
    MyCallObserver myCallObserver = new MyCallObserver();
    MyVoiceCallSourceObserver myVoiceCallSourceObserver = new MyVoiceCallSourceObserver(myCallObserver);
    MyVoiceCallSourceListObserver myCallSourceListObserver = new MyVoiceCallSourceListObserver(myCallObserver,
    myVoiceCallSourceObserver);
    voicecallManager.subscribe(myCallSourceListObserver);
    List<VoiceCallSource> sources = voicecallManager.getVoiceCallSources();
    for (VoiceCallSource source : sources) {
    System.out.println("Source detected");
    List<Call> callList = source.getCalls();
    System.out.println("Listing calls for source: ");
    for (Call call : callList) {
    try {
    System.out.println("\r\n");
    CallInformation callinfo = call.getCallInformation();
    System.out.println("\t LocalSourceId \t| " + callinfo.getLocalSourceId());
    System.out.println("\t RemoteSourceId \t| " + callinfo.getRemoteSourceId());
    System.out.println("\t CallDirection \t| " + callinfo.getCallDirection());
    System.out.println("\t CallStatus \t| " + callinfo.getCallStatus());
    System.out.println("\t CallType \t| " + callinfo.getCallType());
    System.out.println("\t CreationDate \t| " + callinfo.getCreationDate());
    System.out.println("\t DurationSeconds\t| " + callinfo.getDurationSeconds());
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    } catch (VoiceCallNotAvailableException e) {
    e.printStackTrace();
    } catch (VoiceCallLowLevelException e) {
    e.printStackTrace();
    } catch (CannotSubscribeException e) {
    e.printStackTrace();
    }
    }
    private static class MyCallObserver implements CallObserver {
    public void notify(CallStatusEvent event) {
    System.out.println("App::CallStatusEvent");
    try {
    System.out.println("Call with " + event.getCall().getCallInformation().getRemoteSourceId()
    + " status has changed, new status is " + event.getStatus());
    System.out.println("Call duration is " + event.getCall().getCallInformation().getDurationSeconds());
    } catch (VoiceCallNotAvailableException e) {
    e.printStackTrace();
    } catch (VoiceCallLowLevelException e) {
    e.printStackTrace();
    }
    }
    }
    private static class MyVoiceCallSourceObserver implements VoiceCallSourceObserver {
    private MyCallObserver callObserver;
    public MyVoiceCallSourceObserver(MyCallObserver myCallObserver) {
    callObserver = myCallObserver;
    }
    public void notify(VoiceCallSourceEvent evt) {
    System.out.println("App::VoiceCallSourceEvent");
    if (evt instanceof NewCallEvent) {
    NewCallEvent event = (NewCallEvent) evt;
    try {
    event.getCall().subscribe(callObserver);
    } catch (CannotSubscribeException e) {
    e.printStackTrace();
    }
    System.out.println(" App::New call");
    } else if (evt instanceof VoiceCallSourceStatusEvent) {
    VoiceCallSourceStatusEvent event = (VoiceCallSourceStatusEvent) evt;
    System.out.println(" App::Source new status: " + event.getSourceStatus());
    }
    }
    }
    private static class MyVoiceCallSourceListObserver implements VoiceCallSourceListObserver {
    private MyCallObserver callObserver;
    private MyVoiceCallSourceObserver voiceCallSourceObserver;
    public MyVoiceCallSourceListObserver(MyCallObserver myCallObserver,
    MyVoiceCallSourceObserver myVoiceCallSourceObserver) {
    callObserver = myCallObserver;
    voiceCallSourceObserver = myVoiceCallSourceObserver;
    }
    public void notify(VoiceCallSourceListEvent event) {
    System.out.println("App::VoiceCallSourceListEvent");
    if (event.getAction() == VoiceCallSourceListEvent.VoiceCallSourceListAction.ADDED) {
    System.out.println(" App::Voice call source with added");
    try {
    event.getSource().subscribe(voiceCallSourceObserver);
    for (Call call : event.getSource().getCalls()) {
    call.subscribe(callObserver);
    }
    } catch (CannotSubscribeException e) {
    e.printStackTrace();
    }
    }
    }
    }
    }

  • Make a call with the first source in the list, subscribe to call status changes and finish it after 30 seconds.
    package com.gmv.its.dpyjavaexamples.voicecall;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import com.gmv.its.deepsy.voicecall.DeepsyVoiceCallManager;
    import java.time.Instant;
    import java.time.ZonedDateTime;
    import java.time.ZoneOffset;
    class MyCallStatusObserver implements CallObserver {
    public void notify(CallStatusEvent event) {
    try {
    System.out.println("Call with " + event.getCall().getCallInformation().getRemoteSourceId() + " status has changed, new status is " + event.getStatus());
    System.out.println("Call duration is " + event.getCall().getCallInformation().getDurationSeconds());
    } catch (VoiceCallLowLevelException e) {
    e.printStackTrace();
    } catch (VoiceCallNotAvailableException e) {
    e.printStackTrace();
    }
    }
    }
    public class MakeAcallApp {
    private static Call MakeVoipCallFromSource(VoiceCallSource source)
    {
    try {
    // We need to configure source settings for connecting.
    // This may be only neceessary the first time
    source.setCallConfiguration(new VoiceCallConfiguration(VoiceCallConfiguration.CallParameter.SIP_ACCOUNT, "<sip:root@localhost>;regint=0;"));
    source.setCallConfiguration(new VoiceCallConfiguration(VoiceCallConfiguration.CallParameter.SIP_LOCAL_PORT, "5001"));
    source.setCallConfiguration(new VoiceCallConfiguration(VoiceCallConfiguration.CallParameter.RTP_LOCAL_PORT_RANGE, "10000-10010"));
    source.setCallConfiguration(new VoiceCallConfiguration(VoiceCallConfiguration.CallParameter.SIP_CODECS, "G711,OPUS"));
    return source.makeCall("user@127.0.0.1");
    } catch (VoiceCallNotAvailableException e) {
    e.printStackTrace();
    } catch (VoiceCallLowLevelException e) {
    e.printStackTrace();
    }
    return null;
    }
    private static Call MakePhoneCallFromSource(VoiceCallSource source)
    {
    try {
    return source.makeCall("689707485");
    } catch (VoiceCallNotAvailableException e) {
    e.printStackTrace();
    } catch (VoiceCallLowLevelException e) {
    e.printStackTrace();
    }
    return null;
    }
    public static void main(String[] args) {
    System.out.println("Using voice call manager at 192.168.1.140");
    try (VoiceCallManager voicecallManager = DeepsyVoiceCallManager.getInstance("192.168.1.140")){
    List<VoiceCallSource> sources = voicecallManager.getVoiceCallSources();
    if (!sources.isEmpty()) {
    VoiceCallSource source = sources.get(0);
    System.out.println("Performing call with first source in voice call source list");
    // Depending on the source, we will configure it and make a call according to its type
    Call myCall = null;
    if(source.getId().contains("baresip"))
    {
    myCall = MakeVoipCallFromSource(source);
    }
    else
    {
    myCall = MakePhoneCallFromSource(source);
    }
    myCall.subscribe(new MyCallStatusObserver());
    CallInformation myCallinfo = myCall.getCallInformation();
    System.out.println("\t LocalSourceId \t|" + myCallinfo.getLocalSourceId());
    System.out.println("\t RemoteSourceId \t|" + myCallinfo.getRemoteSourceId());
    System.out.println("\t CallDirection \t|" + myCallinfo.getCallDirection());
    System.out.println("\t CallStatus \t|" + myCallinfo.getCallStatus());
    System.out.println("\t CallType \t|" + myCallinfo.getCallType());
    System.out.println("\t CreationDate \t|" + myCallinfo.getCreationDate());
    System.out.println("\t DurationSeconds\t|" + myCallinfo.getDurationSeconds());
    try {
    Thread.sleep(30000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    if(myCall.getCallInformation().getCallStatus() != CallStatus.FINISHED) {
    System.out.println("Finishing call with " + myCall.getCallInformation().getRemoteSourceId() + "after 30 seconds ");
    myCall.finishCall();
    }
    }
    } catch (VoiceCallNotAvailableException e) {
    e.printStackTrace();
    } catch (VoiceCallLowLevelException e) {
    e.printStackTrace();
    } catch (CannotSubscribeException e) {
    e.printStackTrace();
    }
    }
    }

  • Retrieve call configuration parameters from first voice call source in the list
    package com.gmv.its.dpyjavaexamples.voicecall;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import com.gmv.its.deepsy.voicecall.DeepsyVoiceCallManager;
    public class RetrieveCallConfParamsApp {
    public static void main(String[] args) {
    System.out.println("Using voice call manager at 192.168.0.86");
    try (VoiceCallManager voicecallManager = DeepsyVoiceCallManager.getInstance("192.168.0.86")) {
    List<VoiceCallSource> sources = voicecallManager.getVoiceCallSources();
    if (!sources.isEmpty()) {
    VoiceCallSource source = sources.get(0);
    List<VoiceCallConfiguration.CallParameter> parameterList = new ArrayList();
    parameterList.add(VoiceCallConfiguration.CallParameter.NUM_OF_RINGS);
    parameterList.add(VoiceCallConfiguration.CallParameter.AUTOMATIC_ANSWER);
    parameterList.add(VoiceCallConfiguration.CallParameter.AUDIO_MODE);
    parameterList.add(VoiceCallConfiguration.CallParameter.RINGTONE);
    List<VoiceCallConfiguration> configList = source.getCallConfiguration(parameterList);
    System.out.println("Retrieving configuration list for first source in list, source id :");
    for(VoiceCallConfiguration parameter : configList) {
    System.out.println("Parameter " + parameter.getParameter() + " value " + parameter.getValue());
    }
    }
    } catch (VoiceCallNotAvailableException e) {
    e.printStackTrace();
    } catch (VoiceCallLowLevelException e) {
    e.printStackTrace();
    }
    }
    }