If you have come so far, you possibly may have heard what RTMP is: The Real-Time Messaging Protocol (RTMP) was designed for high-performance transmission of audio, video, and data. And now it’s possible and so easy to use RTMP in native iOS applications.

Today we are happy to announce that AntMedia RTMP iOS SDK is ready for developers and end-user applications. This post covers how to run the Reference RTMP Application. If you just would like look for SDK document then please check from here.

Let’s Get Started with Reference Application

Prerequisites

In order to use RTMP iOS SDK, you need LFLiveKit framework build, and some other libraries for sure and Ant Media Server Enterprise Edition. Please contact us at contact@antmedia.io. We can provide Enterprise Edition for trying or personal use.

Start the Ant Media Server Enterprise Edition
Extract the Media Server Enterprise Edition and start the server with start.sh command in the terminal:

cd /path/to/ant-media-server
./start.sh

Introduction to Reference Application

After download reference application project, you may see that project has two view controllers to show: WelcomeViewController to set server ip and room name. VideoViewController to for the streaming.

How to Use RTMP in Native iOS App? 1

And as you can see from project navigator, reference application uses pod for dependency management. LFLiveKit library is used to handle RTMP connection between iOS client and Ant Media Enterprise Edition.

How to Use RTMP in Native iOS App? 2

As it can be seen from the folder structure, there is an only linked library along with LFLiveKit: libstdc++.tbd

So when we run the reference application, WelcomeViewController will be seen as initial view controller. Before taping the connect button, server id and room name should be defined.

How to Use RTMP in Native iOS App? 3

If connection is okay, reference application saves server ip and room name for further sessions. You may have want to check utils for details.

If connection is not okay, an error message will be seen as alert. And if you check WelcomeViewController, you will see that how to deal with RTMP client, means delegation.

If everything if fine, VideoViewController will be presented. For streaming, application will need camera and microphone. Permission request will be prompted. If user not granted, video view controller will not be presented.

As you can see from the storyboard, you can switch camera. Enable or disable video filter like beauty filter. And you can see the status of connection from the header view as well.

Setting Other Peer

The other peer should connect to same room in order to create a peer to peer connection.

You may install the reference application to any other iOS device and connect to same room id or you may go to the http://localhost:5080/LiveApp/play.html?name=, write same room id instead of .

How to Use RTMP in Native iOS App? 4

You will see this message. So when you start streaming from Reference Application, this page will be refreshed automatically.

More Information about iOS RTMP SDK

Take a look at the WelcomeViewController to see the sample usage of the iOS SDK.

Connection Parameters
– streamId (Broadcast name)
– url (Url of AntMedia Server)

AntMedia server URLs may change according to communication medium, for example in secure environment, URL starts with “wss” instead of “ws” also port number changes to “5081” by default it is “5080”.

LFLiveKit Implementation

First, you need to import LFLiveKit SDK along with libstc++.tbd.

Then in your view controller class, create a LFLiveKit instance like:


var session: LFLiveSession = {
let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration(for: LFLiveAudioQuality.high)
let videoConfiguration = LFLiveVideoConfiguration.defaultConfiguration(for: LFLiveVideoQuality.low3)
let session = LFLiveSession(audioConfiguration: audioConfiguration, videoConfiguration: videoConfiguration)
return session!
}()

And do not forget to set delegate in viewDidLoad:


override func viewDidLoad() {
super.viewDidLoad()
self.session.delegate = self
}

Than to start streaming, you just need to create url with using stream info like this:


let stream = LFLiveStreamInfo()
stream.url = “rtmp://\(url)/LiveApp/\(room)”
session.startLive(stream)

For the delegation, there 4 methods to implement:


extension WelcomeViewController: LFLiveSessionDelegate {
func liveSession(_ session: LFLiveSession?, liveStateDidChange state: LFLiveState) {
// To handle state changes
}

func liveSession(_ session: LFLiveSession?, errorCode: LFLiveSocketErrorCode) {
// To handle if any error occurs
}

func liveSession(_ session: LFLiveSession?, debugInfo: LFLiveDebug?) {
// Some informations about session
}
}

So that’s all for the documentation. You still see the animations, some tricks to move session from welcome to video view etc.

We hope this tutorial will be helpful for you, if you have any question, just send an email to contact@antmedia.io