Saturday, September 13, 2014

Using JAIN SIP for Android part II

How to register android SIP stack with a server

In this post we are going to register a sip stack with a server, using the JAIN SIP library from previous tutorial . Before a client can start communication with a server it has to indicate its current IP address and the URLs for which it would like to receive calls and messages.

We are going to need to do the following in order to register the stack
  1. Initialize the stack
  2. Send Register packet
  3. Send authentication information

Step -1: Initialize the Stack

Lets start by setting up a new android project in ADT eclipse, create a new blank Activity during the wizard. Lets create a singleton class SipStackAndroid and initialize a SIP stack. This class is going to implement SipListener and corresponding methods to process SIP events.

Step -2: Send REGISTER

The following method sends a Register packet to server.

Step -3: Send authentication information

In response to the REGISTER packet, server asks for authentication information. Which will be received in processResponse() method. The code snippet below sends back authentication to server.
Helper classes like AccountManagerImpl can be found in JAIN-SIP examples.

In the next post we are going to make a basic android SIP messenger which will be able to receive/send SIP MESSAGE.

Monday, September 8, 2014

Using JAIN SIP for Android part I

Why do this?

  • Limitations of native sip stack.
Native android sip stack is built on top of JAIN SIP stack but it does not have all the functionality, there is no support for IM, presence and video calls right now. Google forked the SIP Stack and never really updated the SIP API that is shipped by default and using the same package names as the original JAIN SIP project instead of renaming to google.com proved to be a major hassle to developers that wanted to add SIP capabilities worldwide as they couldn't use JAIN SIP out of the box.
An opensource implementation of the stack can be found here. It is a java based SIP stack which allows you to integrate the sip stack seamlessly in your android application without the hassle of NDK.
  • A Complete SIP Stack
JAIN SIP is a full implementation of the RFC 3261 Specification and as well as support for several SIP RFCs.

What is the issue using the existing JAIN SIP stack?

JAIN SIP uses package name javax which  is also used by android's native sip stack implemented by google. So if JAIN SIP libraries are used in an android application, it causes a conflict and causes a runtime exception. <insert runtime exception when try to use JAIN SIP libraries>

Using ANT to compile SIP library for  android?

In order to solve the package name conflict, the ant script is modified to output the libraries which can be used in your android application. To compile android library from the package you are going to need ANT . After you have setup ant, test it in your command prompt with

c:\> ant -version
Apache Ant(TM) version 1.9.2 compiled on July 8 2013

If you see a similar output you are good to go ahead. Next step is to use the ant script below, change your directory to where you downloaded JAIN SIP Stack and run ant all.

c:\>ant all
if everything goes well, libraries for android will be placed at dist\android\android-sip-stack.jar.

How to use JAIN SIP in an android project?

In your android application use the jar created by the ant script and include as an external jar. In the next post we are going to see how to register a SIP client in an android application using the stack.