Welcome to the second part of this tutorial series! In previous post, we have talked about how to compile pjsip, and run the built in demo on a real device.
And after this tutorial, you’ll be able to make your 1st VoIP call via the demo we compiled before.
To actually make VoIP calls, we’re going to setup a VoIP server on your own mac. Since testing VoIP calls takes 2 devices, we’ll create a console app on the Mac to receive the phone call, and use iPhone to actually call it.
In this tutorial, you’ll learn:
- Setting up a VoIP server to handle sip requests
- Using PJSUA-CLI to make VoIP calls
To simplify the process so that you could start making VoIP calls immediately, we’ll just simply provide the sourec code of the console VoIP receiver app here. For further detail, we’ll cover it in our next tutorial.
And for the VoIP server, we’re going to use Kamailio.
What’s Kamailio
Here is the definition of Kamailio from the official website:
Kamailio® (former OpenSER) is an Open Source SIP Server released under GPL, able to handle thousands of call setups per second.
Among features:
asynchronous TCP, UDP and SCTP, secure communication via TLS for VoIP (voice, video); WebSocket support for WebRTC; IPv4 and IPv6; …It can be used to build large VoIP servicing platforms or to scale up SIP-to-PSTN gateways, PBX systems or media servers like Asterisk™, FreeSWITCH™ or SEMS…
So, simply put, Kamailio is a great open source VoIP server. Once we successfully deployed and configured Kamailio, our VoIP clients can make VoIP calls to each other via it.
Download and install
To simplify the process, we’ll use Mac directly as the server, instead of a dedicated Linux server like CentOS.
So let’s download the latest source of kamailio from its official website. As the time of writing, it’s 4.1.4.
After unzipping the downloaded source, enter the directory and run the following command to compile and install it:
$ ./make_and_install compile && ./make_and_install install "standard"
It will be installed to /usr/local automatically. To be specific, the binary file will be installed to“/usr/local/sbin/kamailio”
Configure kamailio
Beore starting kamailio service, you need to create the kamailio.cfg file. You could download a sample configuration file here, and save it to:
/usr/local/etc/kamailio/kamailio.cfg
You can now go ahead and start running kamailio:
/usr/local/sbin/kamailio
You’ll see output similar to the following:
This means your kamailio has been successfully started, and it’s listerning on port 5060. You can now connect your VoIP clients to it and start making VoIP calls.
Create a console VoIP receiver app on your Mac
In order to enable you to make VoIP calls sooner, we’re not going to explain the details for now (of course, if you’re interested, you could try to understand the code yourself). We’ll cover the details in the next tutorial.
Download the source code of the VoIP receiver app I wrote here.
After unzip the file, go into the directory and compile it:
make
You’ll get the executable receiver in the folder.
Actually make VoIP calls
Great, now both the clients and the server are ready, let’s make some VoIP calls.
First of all, let’s launch the receiver app on Mac:
./receiver
After a bunch of messages, you’ll see something like the following:
This means the receiver@localhost has been successfully registered on our SIP server.
Next, open the demo app we compiled previously (it’s ipjsua if you didn’t change the name), check the text on the bottom of the screen, and then telnet to it from your mac based on the info:
telnet 192.168.43.166 2323
Finally, let’s send the command to actually make our 1st VoIP call. Since the receiver is listening on port 5080, and the IP address of the Mac is 192.168.43.106 in this case. To make a VoIp call, we’re going to use this command:
call new sip:192.168.43.106:5080
After 1~2 seconds, your iPhone and your Mac will establish the VoIP call, you can then hear the voice from iPhone on Your mac and vice versa.