How we brought VoIP to our iPhone app
Written by Jeroen van Veen on 10th May 2016
As the creators of an awesome VoIP platform, we really wanted to get VoIP to the smartphones. We believe that your desktop phone is solid, has a proven quality and will stay for a while, but nowadays more and more people are always on the move. And they want to be available for their business everywhere. They bring along their laptop and telephone and travel from the office to a coffeeshop, clients or abroad. To make sure they have happy customers, their company needs to be easily reachable by phone. That’s why we implemented the possibility to transfer incoming calls to a mobile number a few years ago.
Getting beyond the two-step call
As a company, you might not want to hand out personal mobile numbers to your clients, or you want to have all the costs of business calls on one bill. For these reasons we created an app that will setup a two-step call, which calls the mobile number of your employee first and then connects that call to the client. That works fine, but it is not the best experience. People have to answer an incoming call first before connecting to the second call, there are double costs involved because of the two different calls and the sound quality could be better.
Searching for a SIP library
So about 18 months ago we started doing research. We knew you can create a softphone on a smartphone. Skype has done it for many years, WhatsApp introduced it not so long ago and there are other implementations less known. As a company that loves open source, we started looking for a library that is open source, could be implemented on iOS and Android and uses SIP. Our Asterisk platform is based on SIP, and implementing another backend would be cumbersome and probably unnecessary.
The first SIP calls
We found PJSIP. A library for many platforms, actively maintained, open source and with all the features we thought were needed for our goals. For the implementation we looked a bit further and found Gossip. A no longer maintained, but good wrapper around the c/c++ library of PJSIP for iOS. We tried to implement Gossip into our project and were pretty successful. We had our first SIP calls in a very early stage and we were confident this was the way to go. But the implementation lacked one important feature: how do we keep the connection alive to our servers and get incoming calls? Apple prohibits apps to stay awake in the background all the time and kills connections after a while if the app is no longer running in the foreground.
Creating our own middleware
Luckily Apple created VoIP Push in iOS 8, that came out just a couple of months after the start of our project. VoIP Push is a high priority push message system that can send messages to your app, gives you runtime to set up connections and be available for incoming calls. So we created our own middleware (private repository, but will be public very soon). The middleware will get a notification from Asterisk, will send a message through Apple to the device, the device will respond OK if the connection could be setup and the middleware will tell Asterisk to deliver the call to the phone.
Aiming for the best experience
This roundtrip meant implementing stuff on Asterisk, creating a high available webserver, find out what was necessary to push messages via Apple and create extra logic in the app. So all in all, delay… But: it also created a much better experience, calls could be delivered a lot better and we were no longer pushing the app to stay alive as much as possible and kill the battery life of the phone.
The making of VialerSIPLib-iOS
However, Gossip was built before VoIP Push and had no really good implementation of starting and stopping the service (it was meant to run the whole lifetime of the app). We had two solutions, contribute to Gossip by changing it to our needs, or create our own wrapper. Because Gossip is not actively maintained and we had a quite other way we needed the library, we choose to create VialerSIPLib-iOS. We got the best parts of Gossip and also of Telephone and Swig. We created our own CocoaPods, which we will release to CocoaPods.org.
Time for a beta release
After a lot of internal testing, we thought it was time to release a beta version of the Vialer app with SIP. We asked our resellers to try the app and find clients who wanted to use a beta version of our app and have fun with it. We will watch our monitoring tools, social media and email to see what the reactions are and hope we can bring this awesome new feature to all our clients as soon a possible.
How about Android?
A side note: Android is not forgotten! We are working hard on a beta version of our Android app that has PJSIP in it. We think we can start the beta version for Android next Monday.
Every part of this project is open source or will be open source in the near future and we’re proud of that fact. We hope you’ll find inspiration, use our apps or parts of our apps. If you have any thoughts on this already, please let me know in the comments below.
Written by Marian on 12th October 2016
Your idea is great and is convergent with my thoughts about VoIP push application. Please send me your middleware source when it will be available for public.