How to Make an iOS VoIP App With Pjsip: Part 5
来源:互联网 发布:淘宝睡衣哪家好 编辑:程序博客网 时间:2024/06/14 05:07
Welcome to the 5th part of this tutorial series!
In the previous tutorial, we have created an iOS project, and made pjsip functions ready to be called. In today’s tutorial, we are going to actually call those pjsip functions from our iOS app.
In case you’re new to this series, here is a quick recap of previous tutorials:
- Part 1: How to compile pjsip and run the embeded demo on your iOS device
- Part 2: How to set up your own VoIP server via Kamailio, and actually make VoIP call between an iOS device and a Mac.
- Part 3: A brief introduction of pjsip API, by digging into the source code of a very simple Mac VoIP program.
- Part 4: How to add the pjsip libraries and header files into your own iOS project, so that you can call pjsip API from your app.
You could download the source code of this project (starting from the 4th tutorial) on Github here. Each commit of the project, is representing one step of the tutorial.
Adding XCPjsua.c and XCPjsua.h
As we mentioned before, the interfaces of pjsip functions are in C. So in order to call pjsip methods, normally, we would create a C file to encapsulate invocation of pjsip methods, and then expose the methods of this C file via a header file.
Create a new Header File, and name it XCPjsua.h
Then, create a new C File, and name it XCPjsua.c
Your project will look like this afterwards:
Starting pjsua
In the XCPjsua.h, add the following declaration of startPjsua() method:
In the XCPjsua.c, add the following code to implement this startPjsua() method:
This code is almost the same as what we’ve discussed in the 3rd post. If you don’t understand any part of it, you could probably find your answer in that post.
We have 2 main differences here:
- We made the account id – “pjsua_acc_id acc_id” – a static variable. Because we’ll need this acc_id to make VoIP call later.
- We parameterized the sipUser and the sipDomain, so that we could easily connect to different VoIP servers in differnt userNames.
Make VoIP call and end VoIP call
Declare the makeCall() and endCall() in the XCPjsua.h
And add the following code in XCPjsua.c to implement them:
The code itself should be quite straight forward. We simply make use of thepjsua_call_make_call() and the pjsua_call_hangup_all() to make call and end call.
The acc_id being used in pjsua_call_make_call() is the global variable we declared before.
Define PJ_AUTOCONF
You should be able to compile and run this app in the simulator now. (But 64-bit simulator is not supported yet, becasue we didn’t include the x86-64 architecture in our fat pjsip library. We only included the i386 architecture, which is for 32-bit simulator).
However, if you try to build and run it on a real device, you’ll get compile error like the following:
User Defined Issues: "Please specify target machine."
Basically, it’s asking you to specify a target architecture. But we could let pjsip do it automatically for you:
Go to the “Build Settings”, and add PJ_AUTOCONF macro in the Preprocessor Macros field.
Try again, and you’ll be able to run this project on your own iPhone!
Initialize pjsip and actually make VoIP call
After all these hard prepartion work, it’s super easy now to initialize pjsip and make our VoIP call.
Start the local Kamailio server on your Mac, and run the mac receiver for receiving the incoming call (If you forgot how to do this, you could get more info in the second tutorial). And then, check the IP of your Mac, which would be the IP of your SIP server, and also the IP of your receiver.
Next, add this import statement at the beginning of your XCAppDelegate.m:
And add the following code in the didFinishLaunchingWithOptions method ofXCAppDelegate.m. In my case, the IP of my Mac is 192.168.43.106, you should change it according to your own IP.
The port being used here – 5080 – is the port the receiver program listening to.
Now, go ahead to compile and run your app on your iPhone. When the app launches, it will register itself on your SIP server, and make call to the receiver program. You will then be able to hear your voice from your iPhone on your Mac and vice versa!
- How to Make an iOS VoIP App With Pjsip: Part 5
- How to Make an iOS VoIP App With Pjsip: Part 1
- How to Make an iOS VoIP App With Pjsip: Part 2
- How to Make an iOS VoIP App With Pjsip: Part 3
- How to Make an iOS VoIP App With Pjsip: Part 4
- ios php mysql How To Make an iPhone App with MySQL and WordPress
- How to Make an HTML5 iPhone App
- How to Make an HTML5 iPhone App
- How to make an icon spin with CSS
- How to make an altcoin
- How to Make a Gesture-Driven To-Do List App Like Clear: Part 1/3
- Rotating Turrets: How To Make A Simple iPhone Game with Cocos2D Part 2
- Harder Monsters and More Levels: How To Make A Simple iPhone Game with Cocos2D Part 3
- Collisions and Collectables: How To Make a Tile Based Game with Cocos2D Part 2
- How To Make A Simple Multiplayer Game with Game Center Tutorial: Part 2/2
- How To Make A Simple Multiplayer Game with Game Center Tutorial: Part 1/2
- raywenderlich-Rotating Turrets: How To Make A Simple iPhone Game with Cocos2D Part 2
- How to Make an HTTP Connection Using TCP/IP with RSocket
- 建立可互换的Locks
- ATS(应用传输安全)
- HDU 1008
- 使用C++在CAD中添加菜单栏(ObjectARX)
- aerospike性能测试
- How to Make an iOS VoIP App With Pjsip: Part 5
- windows下tomcat性能优化总结
- JavaScript中双叹号(!!)作用
- 【面试题】在O(1)时间复杂度删除链表节点
- HTTP Streaming with FFMpeg and an Open Source Segmenter
- Matlab--函数极值最值零点
- PAT (Advanced Level) 1065. A+B and C (64bit) (20) 溢出判断
- 图的深度遍历
- HDU 2039 三角形