您的位置:首页 > 移动开发 > IOS开发

How to Make an iOS VoIP App With Pjsip: Part 2

2015-07-28 14:39 846 查看
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

loading modules under /usr/local/lib64/kamailio/modules/
Listening on
udp: 127.0.0.1:5060
udp: 127.94.0.1:5060
udp: 127.94.0.2:5060
udp: 192.168.43.106:5060
tcp: 127.0.0.1:5060
tcp: 127.94.0.1:5060
tcp: 127.94.0.2:5060
tcp: 192.168.43.106:5060
Aliases:
tcp: 106.43.168.192.in-addr.arpa:5060
tcp: 1.0.0.127.in-addr.arpa:5060
tcp: localhost:5060
udp: 106.43.168.192.in-addr.arpa:5060
udp: 1.0.0.127.in-addr.arpa:5060
udp: localhost:5060

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:

1
2
3

16:37:22.631    pjsua_acc.c  ....SIP outbound status for acc 0 is not active
16:37:22.631    pjsua_acc.c  ....sip:receiver@localhost: registration success, status=200 (OK), will re-register in 300 seconds
16:37:22.631    pjsua_acc.c  ....Keep-alive timer started for acc 0, destination:127.0.0.1:5060, interval:15s

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.


To be continued…

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: