Skip to content

llenroc/TwilioXamarinRoomsSampleIOS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Twilio Video Quick Start for Xamarin.iOS in CSharp

This is based off the Swift iOS Sample

NOTE: This application uses Twilio's new Programmable Video Rooms API, which is currently available in Beta. The docs are here.

Up and Running

To get started, we'll make a 1:1 video call between the iPhone simulator in XCode and your own iOS device.

  1. Download this project and restore packages.

  2. Create a Twilio Video Configuration Profile in the Twilio Console. If you haven't used Twilio before, welcome! You'll need to Sign up for a Twilio account. It's free!

  3. Generate an Access Token in the Twilio Console. Pick a name for your user identity (such as "Alice"). Leave this web page open, because you'll use it as the other side of the video chat.

  4. Copy and paste the access token into ViewController.cs.

  5. Build and run the app on a physical device (iPhone, iPod Touch, etc.)

  6. On the same web page where you generated the token, generate another Access Token for another identity (such as "Bob")

  7. Copy and paste the access token into ViewController.cs (replacing the one you used earlier).

  8. Build and run the app on a second physical device if you have one, or the iPhone simulator.

  9. Once you have both apps running, enter an identical Room name (such as "MyRoom") into both apps, and tap "Connect" to connect to a video Room (you'll be prompted for mic and camera access on the physical device). Once you've connected from both devices, you should see video! (Since the iPhone Simulator doesn't have a camera you'll only see video in one direction if you're using that environment.)

What is this project?

This project consists of two sample apps: one using CallKit, and one without CallKit support.

The quick starts will help you get video chat integrated directly into your iOS applications using Twilio's Video SDK. These examples are for Swift developers - if your app uses Objective-C see video-quickstart-objective-c.

The sample apps are written in Swift 3.0. You will need at least Xcode 8.0 in order to run the applications.

Review the code to see how how to set up key classes like TVIVideoClient, TVIRoom, TVIParticipant, TVILocalMedia, and TVICameraCapturer. The ViewController implements the TVIRoomDelegate, and TVIParticipantDelegate protocols in order to display remote Participant video on screen.

Prerequisites

This project uses C# 6 and Xamarin.iOS, and the only supported way to develop iOS apps is on an Apple computer running OS X and Xcode. We have tested this application with the latest versions of iOS (10.2) and Xcode (8.0) at the time of this writing.

You can use the iOS Simulator that comes with Xcode to do your testing, but local video will not be shared since the Simulator cannot access a camera. If you have an iOS device, you can now run apps from Xcode on your device without a paid developer account.

Twilio Library Setup for the Project

You will need to add the Twilio Video library to the project to compile and run. You can do this using the Cocoapods dependency management system. Version 1.0 or greater is required.

Access Tokens and Servers

Using Twilio's Video client within your applications requires an access token. These access tokens can come from one of two places:

  1. You can create a one-time use access token for testing in the Twilio Console. This access token can be hard-coded directly into your mobile app, and you won't need to run your own server. This works for local development and testing, but isn't a solution for a production environment.

  2. When you're ready to take the next step, you can run your own server that provides access tokens using your Twilio credentials. This server can either run locally on your development machine, or it can be installed on a server. If you run the server on your local machine, you can use ngrok to give the server an externally accessible web address. That way, you can run the quick start app on an actual device, instead of the iOS Simulator.

Generating an Access Token in Twilio's Console

The first step is to Generate an Access Token from the Twilio developer console. Use whatever clever username you would like for the identity. You will get an access token that you can copy and paste into ViewController.swift.

Generating an Access Token With Azure Functions

Consider using Azure Functions and the unofficial token generator.

Setting up a Video Chat Web Server

If you want to be a little closer to a real environment, you can download one of the video quickstart applications - for instance, Video Quickstart: PHP and either run it locally, or install it on a server.

You'll need to gather a couple of configuration options from your Twilio developer console before running it, so read the directions on the quickstart. You'll copy the config.example.php file to a config.php file, and then add in these credentials:

Credential Description
Twilio Account SID Your main Twilio account identifier - find it on your dashboard.
Twilio Video Configuration SID Adds video capability to the access token - generate one here
API Key Used to authenticate - generate one here.
API Secret Used to authenticate - just like the above, you'll get one here.

A Note on API Keys

When you generate an API key pair at the URLs above, your API Secret will only be shown once - make sure to save this in a secure location.

Running the Video Quickstart with ngrok

Because we suggest that you run your video chat application on actual iOS device so that you can use the camera on the device, you'll need to provide an externally accessible URL for the app (the iOS simulator will be fine with localhost). Ngrok creates a publicly accessible URL that you can use to send HTTP/HTTPS traffic to a server running on your localhost. Use HTTPS to make web connections that retrieve a Twilio access token.

When you get a URL from ngrok, go ahead and update ViewController.swift with the new URL. If you go down this path, be sure to follow the directions in the comments in the viewDidLoad() method at the top of the source file - you will need to uncomment one line, and comment out another. You will also need to update the code if your ngrok URL changes.

For this quick start, the Application transport security settings are set to allow arbitrary HTTP loads for testing your app. For production applications, you'll definitely want to retrieve access tokens over HTTPS/SSL.

Have fun!

This is an introduction to Twilio's Video SDK on iOS. From here, you can start building applications that use video chat across the web, iOS, and Android platforms.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages