Guides

This guide is out of date.

We are no longer supporting this mobile guide. It is still here strictly for informational purposes. We do not expect this guide to still work.

Using Cordova with iOS and WebRTC

Requirements

To create a hybrid native iOS WebRTC app you will need:

The Cordova plugin includes WebRTC libraries for iOS, SIP.js, a custom media handler to use the iOS WebRTC libraries, and a Cordova build script to build and run the project on devices.

Project Setup

Install Cordova

Open terminal and navigate to the directory you want to create your project in. Run the following commands to create a Cordova iOS project. Replace Cordova-SIPjs with your own project name.

cordova create Cordova-SIPjs

cd Cordova-SIPjs

cordova platform add ios

Add the OnSIP Cordova Plugin

Run the following command to add the PhoneRTC WebRTC library to your Cordova project.

cordova plugin add https://github.com/onsip/onsip-cordova.git

HTML and Javascript

The HTML and Javascript required to use the plugin is very similar to regular SIP.js applications that would run in the browser. The only difference is that you need to set the app to use the plugin installed SIP.js and MediaHandler.

// Use plugin version of SIP.js
var SIP = cordova.require("com.onsip.cordova.Sipjs");

// Use plugin version of MediaHandler
var PhoneRTCMediaHandler = cordova.require("com.onsip.cordova.SipjsMediaHandler")(SIP);

// Set my UA to use the MediaHandler
var ua = new SIP.UA({
  mediaHandlerFactory: PhoneRTCMediaHandler
});

Running the project

Running project from Command Line

Ensure your device is plugged into your computer and provisioned for development. Then run the following command.

cordova run ios

Running project from XCode

The architecture needs to be set to armv7. This is because the WebRTC libraries that are included are precompiled for this architecture. Trying to compile the libraries with other architectures will cause a linker error and your project will not compile. Open the platforms folder then the ios folder. In the ios folder you will see an xcodeproj. Open the xcodeproj with XCode. In XCode navigate to the build settings for CordovaLib.xcodeproj.

Set Build Active Architecture Only to No

Set Valid Architectures to armv7

Navigate to the build settings for HelloCordova.xcodeproj.

Set Build Active Architecture Only to No

Set Valid Architectures to armv7

Known limitations

These are currently the known limitations of the Cordova Plugin:

Troubleshooting

If you have difficulty, please reach out to us on our mailing list or open an issue on the project’s GitHub page.