Recently, we have shared a post about WebRTC Android SDK. Today we are happy to announce AntMedia WebRTC iOS SDK is ready for developers.

Similar to Android SDK, iOS SDK, simplifies to use WebRTC on iOS Platform, provides peer to peer WebRTC communication between iOS devices (iPhone and iPad) and browsers by using Ant Media server as a signaling server. This document describes first how to run the Reference Application. If you just would like look for SDK then please check SDK documentation from here.

Let’s Start with Reference Application

Prerequisites

In order to use WebRTC iOS SDK, you need WebRTC framework build, WebRTC iOS SDK and some other libraries for sure and Ant Media Server Enterprise Edition. Please contact us at contact@antmedia.io. We can provide WebRTC iOS SDK and Enterprise Edition for trying or personal use. Please do not forget to mention where you prefer to use WebRTC iOS SDK: Simulator or generic iOS device.

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, connection mode and room name. VideoViewController to show local and remote streams.

How to Use WebRTC SDK in Native iOS App? 1

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

How to Use WebRTC SDK in Native iOS App? 2

As you can see from the folder structure, there are some linked libraries with AntMediaSDK and WebRTC: AVFoundation, GLKit, CoreVideo, CoreMedia, CoreImage, CoreGraphics, AudioToolbox, VideoToolbox, libc++, libsqlite3.0, libicucore.

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. Please do not forget to add protocol for server id.

How to Use WebRTC SDK in Native iOS App? 3

If connection is okay, reference application saves server ip and room name for further sessions.

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

If everything if fine, VideoViewController will be presented. If mode is not play, means that application will need camera and microphone for local stream, permission request will be prompted.

As you can see from the storyboard, you can enable and disable camera & microphone. And you can see the status of connection from the footer 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/WebRTCAppEE/peer.html, write same room id in the textbox and click “join” on the web page.

How to Use WebRTC SDK in Native iOS App? 4

More about iOS WebRTC SDK

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

Modes

There are 3 types of broadcast scenarios, therefore, operating modes.
– Peer Connection (Two nodes connect to each other, 1-1 connection)
– Publish (One node publishes, 1-N connection)
– Play (Other nodes play broadcast from publisher,1-N connection)

According to the projects or needs, the developer can implement one or all modes in their applications.

Connection Parameters

– streamId (Broadcast name)
– url (WebSocket Url of Server)
– mode (Operating Modes)

WebSocket 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 “8082” by default it is “8081”

AntMediaClient Implementation

First, you need to import AntMediaSDK and WebRTC along with AVFoundation, GLKit, CoreVideo, CoreMedia, CoreImage, CoreGraphics, AudioToolbox, VideoToolbox, libc++, libsqlite3.0, libicucore.

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

let client = AntMediaClient.init()

You can see the WelcomeViewController how to init AntMediaClient: If server url, room name and mode is okay, clientDidConnect will be called by SDK.

Then you should set local and remove video views and also delegate, you can VideoViewController:

client.delegate = self
client.setVideoViews(local: localVideoView, remote: remoteVideoView)

So client is ready for connection:

client.connect()

If clientDidConnect will be called that means connection is okay and client is ready to start streaming:

client.start()

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

[Total: 1    Average: 5/5]