linphone-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Linphone-developers] Understand better what I need to setup and use Lib


From: Giacomo Furlan
Subject: [Linphone-developers] Understand better what I need to setup and use LibLinphone on Android
Date: Mon, 05 Oct 2015 15:29:04 +0200
User-agent: Mailbird/ 2.1.17.0

Hello!

I have to create a SIP client which must has to reply as an interphone (so only incoming audio/video calls). To be honest I saw a lack of documentation, because all I was able to find are pieces of code here and there... and I find really difficult to navigate in a so big library as liblinphone.

Now, what I've done so far: in theory I configured the proxy, added it and set as default and started the service via (myLinphoneCoreInstance).iterate(). In details:

1. created a class which handles LinPhone with the following code as construct:

    SIPHandler (Context context) {
        ctx = context;
        enabled = true;

        LinphoneManager.createAndStart(ctx);

        LinphoneCoreListener listener = null;
        try {
            listener = new SIPListener(ctx);
            lc = LinphoneCoreFactory.instance().createLinphoneCore(listener, context);

            LinphoneCore.Transports transports = new LinphoneCore.Transports();
            transports.udp = 8888; // is this in order to LISTEN on port 8888?
            lc.setSignalingTransportPorts(transports);

        } catch (LinphoneCoreException e) {
            e.printStackTrace();
        }
    }


    public void register(String username, String domain) {
        LinphoneCoreFactory lcFactory = LinphoneCoreFactory.instance();

        String identity = "sip:" + username + "@" + domain;

        RelativeLayout mainLayout = (RelativeLayout) ((Activity) ctx).findViewById(R.id.main_layout);

        try {
            LinphoneProxyConfig proxyCfg = lc.createProxyConfig(identity, domain, null, true);
            proxyCfg.enableRegister(true);

            lc.addProxyConfig(proxyCfg);
            lc.setDefaultProxyConfig(proxyCfg);

            Snackbar.make(mainLayout, "LibLinphone correctly setup", Snackbar.LENGTH_LONG).show();
        } catch (LinphoneCoreException e) {
            Snackbar.make(mainLayout, "LibLinphone error was thrown", Snackbar.LENGTH_LONG).show();
            e.printStackTrace();
        }
    }

So far, so good: all goes fine without any error.

Then I start the loop in a separate thread:

callHandler.register("1050", "192.168.0.201");
Runnable loop = new LinPhoneLooper(callHandler);
new Thread(loop).start();

This is the code of LinPhoneLooper:

public class LinPhoneLooper implements Runnable {
    LinphoneCore lc;
    SIPHandler handler;

    public LinPhoneLooper(SIPHandler handler) {
        this.handler = handler;
        this.lc = handler.getCore();
    }

    @Override
    public void run() {
        while (handler.isEnabled()) {
            if (lc != null) {
                lc.iterate();
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

Eventually this is the LinphoneCoreListener implementation (SIPListener), which extends LinphoneCoreListenerBase:

    SIPListener(Context context) {
        ctx = context;
        mainLayout = (RelativeLayout) ((Activity) ctx).findViewById(R.id.main_layout);
    }

    @Override
    public void registrationState(LinphoneCore linphoneCore, LinphoneProxyConfig linphoneProxyConfig, LinphoneCore.RegistrationState registrationState, String s) {
        if (registrationState == LinphoneCore.RegistrationState.RegistrationOk) {
            Snackbar.make(mainLayout, "Registered to SIP service", Snackbar.LENGTH_LONG).show();
        } else {
            Snackbar.make(mainLayout, "" + registrationState, Snackbar.LENGTH_LONG).show();
        }
    }

As I previously wrote, I expected to see the registration work... but I get no registrationState procs (and thus no registration at all). Wireshark even confirms me that there is no network activity at all, so LinPhone is actually stopped.

When I'll figure out how to register, I'll need to know how to receive a call (and setup a View accordingly in order to see and view the streams), but one step per time.

Can you please help me?

Thank you very much!

Giacomo Furlan
Software developer
Software Solutions Designs

reply via email to

[Prev in Thread] Current Thread [Next in Thread]