Desktop Java

Introduction to Zoiper SDK 2.0 Java for desktop

This section explains how to develop your VoIP application with Java on Windows, Linux and macOS in combination with the Zoiper SDK 2.0 Java for desktop. The SDK is an all-inclusive solution for developing VoIP applications for Windows, Linux and macOS with:

  • audio calls (SIP, IAX)
  • video call (SIP)
  • presence
  • messaging
  • call recordings
  • other functionalities

The SDK 2.0 consists of:

  • a dynamic library with all the respective headers in it
  • some helper libraries (e.g. LAME.dll).

Please note that Zoiper SDK 2.0 on Windows depends on VC redistributable package, which must be manually installed in case it is missing from the system (e.g. on some Windows Server versions). Otherwise, the loading of the "zdk.jni.dll" will fail!

Hardware and software requirements

Requirement Description
Processor Intel Core i3 or better
Memory 4GB(minimum) 8 GB(recommended)
Hard disk space 1 GB
Environent Microsoft Visual Studio 2017 or newer
JDK JDK 8 or newer
Operating system (Development environment) Windows, Linux, macOS
Operating system (Runtime environment) Windows 8 or above, Linux, macOS 10.15 or later
Architecture x64

Contents of the SDK package

Folder Description
package/Documentation Contains the html Zoiper SDK Documentation. To open it in your browser, click on the index.html file.
package/RunTest Contains the Zoiper SDK dll and the additional library LAME.dll.
package/ZoiperWinForms Contains all files for the Demo application as well as its settings, properties etc.
package/ZoiperWinForms.sln The actual Demo project. To test Zoiper SDK 2.0, open, build and run the Demo application.

Setting up the Demo project

To be able to run the Zoiper Java for desktop Example, you will need to include the zdk.java as a reference to the project and then to build it. By default zdk.java is not included in the example. If you still don't have the zdk.java library, please contact us on zoiper.com.

Default configuration

By default, the Demo application uses the transport type you select from the GUI. STUN is enabled with these default STUN settings:

  • Server: stun.zoiper.com
  • Port: 4378
  • Refresh period: 30000ms
  • Enabled codecs: u-Law, Opus Wide and VP8

Activation

You need an SDK activation to test the demo. Zoiper SDK 2.0 Java for desktop offers both Online and Offline activation.

if (ctx != null && ActFoldPath == "")
{
    ctx.activation().startSDK(null, tbCertUserName.getText(), tbCertPassword.getText());
}
else if(ctx != null && ActFoldPath != "")
{
    ctx.activation().startSDK(ActFoldPath + "\\certificate", tbCertUserName.getText(), tbCertPassword.getText());
}

Online Activation

To activate the demo online, you need an activation username and password from zoiper.com. Pass your activation credentials in the application to the StartSDK() method as illustrated above.

If the activation is successful, you will receive a result code “OK” from the StartSDK() method. You are now ready to test the Demo. In case the activation fails, the method will return a code with the reason for the failure.

Offline Activation

Follow these steps to activate the demo offline:

  1. Generate a certificate
  2. Send it to register5@zoiper.com
  3. You will receive an activation file via email
  4. Put the activation file in the same directory as the project. Or pass it as a path to the file.

Beware! The first time you run the project and you call the activation, you must call the method to create an offline activation file - createOfflineActivationFileSDK(path, certUserName, certPassword) and pass the respective arguments. On the next start you just need to call the startSDK(path + "\\certificate", certUserName, certPassword) method. Below, you can find a working example from the Demo application:

Create and register your account

A complete example of the function that adds the user and its details is illustrated below:

    account = ctx.accountProvider().createUserAccount();

    account.accountName(tbUserName.getText());

    regCfg = ctx.accountProvider().createAccountConfiguration();

    regCfg.userName(tbUserName.getText());
    regCfg.password(tbPassword.getText());

    if("SIP".equals(cbProtocolType.getText()))
    {
        regCfg.type(ProtocolType.SIP);
        regCfg.sip(ctx.accountProvider().createSIPConfiguration());

        regCfg.sip().transport(TransportType.valueOf(cbTransportType.getText()));

        regCfg.sip().domain(tbServer.getText());
        regCfg.sip().enablePrivacy(chPrivacy.getSelection());
        regCfg.sip().enableSRTP(chSRTP.getSelection());
        regCfg.sip().enableVideoFMTP(chFMTP.getSelection());
        regCfg.sip().enablePreconditions(chPreconditions.getSelection());

        if(chZRTP.getSelection())
        {
            ArrayList<ZRTPHashAlgorithm> hash = new ArrayList<ZRTPHashAlgorithm>();
            hash.add(ZRTPHashAlgorithm.s384);
            hash.add(ZRTPHashAlgorithm.s256);

            ArrayList<ZRTPCipherAlgorithm> cipher = new ArrayList<ZRTPCipherAlgorithm>();
            cipher.add(ZRTPCipherAlgorithm.cipher_aes3);
            cipher.add(ZRTPCipherAlgorithm.cipher_aes2);
            cipher.add(ZRTPCipherAlgorithm.cipher_aes1);

            ArrayList<ZRTPAuthTag> auth = new ArrayList<ZRTPAuthTag>();
            auth.add(ZRTPAuthTag.hs80);
            auth.add(ZRTPAuthTag.hs32);

            ArrayList<ZRTPKeyAgreement> keyAgreement = new ArrayList<ZRTPKeyAgreement>();
            keyAgreement.add(ZRTPKeyAgreement.dh3k);
            keyAgreement.add(ZRTPKeyAgreement.dh2k);
            keyAgreement.add(ZRTPKeyAgreement.ec38);
            keyAgreement.add(ZRTPKeyAgreement.ec25);

            ArrayList<ZRTPSASEncoding> sasEncoding = new ArrayList<ZRTPSASEncoding>();
            sasEncoding.add(ZRTPSASEncoding.sasb256);
            sasEncoding.add(ZRTPSASEncoding.sasb32);

            regCfg.sip().zrtp(ctx.accountProvider().createZRTPConfiguration());
            regCfg.sip().zrtp().enableZRTP(chZRTP.getSelection());
            regCfg.sip().zrtp().hash(hash);
            regCfg.sip().zrtp().cipher(cipher);
            regCfg.sip().zrtp().keyAgreement(keyAgreement);
            regCfg.sip().zrtp().sasEncoding(sasEncoding);
            regCfg.sip().zrtp().auth(auth);
            regCfg.sip().zrtp().cacheExpiry(-1);
        }

        if(chStun.getSelection())
        {
            regCfg.sip().stun(ctx.accountProvider().createStunConfiguration());
            regCfg.sip().stun().stunEnabled(chStun.getSelection());
            regCfg.sip().stun().stunServer("stun.zoiper.com");
            regCfg.sip().stun().stunPort(3478);
            regCfg.sip().stun().stunRefresh(30000);
        }

        if(chRTCFeedback.getSelection())
        {
            regCfg.sip().rtcpFeedback(RTCPFeedbackType.Compatibility); // Include AVP and AVPF video media profiles in the SDP for backward compatibility
        }
        else
        {
            regCfg.sip().rtcpFeedback(RTCPFeedbackType.Off); // Include only AVP video media profile in the SDP
        }

    }
    else if("IAX".equals(cbProtocolType.getText()))
    {
        ctx.addProtocol(ProtocolType.IAX, 4569);
        regCfg.type(ProtocolType.IAX);
        regCfg.iax(ctx.accountProvider().createIAXConfiguration());
        regCfg.iax().host(tbServer.getText());
    }

    ArrayList<AudioVideoCodecs> codecs = new ArrayList<AudioVideoCodecs>();
    codecs.add(AudioVideoCodecs.OPUS_WIDE);
    codecs.add(AudioVideoCodecs.PCMU);
    // This is for the video call
    codecs.add(AudioVideoCodecs.vp8);

    account.mediaCodecs(codecs);
    account.setStatusEventListener(window);
    account.configuration(regCfg);

    UserId = account.createUser();

When the account is created, you can register it with the following function:

Result result = acc.registerAccount();

Changing the account configuration

Transport type

regCfg.sip().transport(transportType);

Possible values:

  • UDP
  • TCP
  • TLS

STUN

if (Stun)
{
    regCfg.sip().stun(ctx.accountProvider().createStunConfiguration());
    regCfg.sip().stun().stunEnabled(chStun.getSelection());
    regCfg.sip().stun().stunServer("stun.zoiper.com");
    regCfg.sip().stun().stunPort(3478);
    regCfg.sip().stun().stunRefresh(30000);
}

Changing the used codecs

ArrayList<AudioVideoCodecs> codecs = new ArrayList<AudioVideoCodecs>();
codecs.add(AudioVideoCodecs.OPUS_WIDE);
codecs.add(AudioVideoCodecs.PCMU);
// This is for the video call
codecs.add(AudioVideoCodecs.vp8);

account.mediaCodecs(codecs);

Possible values:

  • G729
  • GSM
  • iLBC_20
  • h264
  • vp8
  • h264_hwd
  • SPEEX_NARROW
  • SPEEX_WIDE
  • SPEEX_ULTRA
  • G726
  • OPUS_NARROW
  • OPUS_WIDE
  • OPUS_SUPER
  • OPUS_FULL
  • AMR
  • AMR_WB
  • PCMU
  • PCMA
  • G722

Create your desktop Java VoIP App

Creating Zoiper SDK 2.0 Context in your application

To be able to use Zoiper SDK 2.0 in your application, you will have to add a reference to it in your project. Afterwards, you should create a context of the SDK and then to initialize it.

ctx = new Context();

The actual start of the context is usually performed after receiving the callback for successful activation - onContextActivationCompleted.

Result res = ctx.startContext();

Java SDK Reference

You can find the API and method references here.