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