WebRTC SDK for iOS - Kinesis Video Streams

WebRTC SDK for iOS

The following step-by-step instructions describe how to download, build, and run the Kinesis Video Streams WebRTC SDK in iOS and its corresponding samples.

Download the WebRTC SDK in iOS

To download the WebRTC SDK in iOS, run the following command:

git clone https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-ios.git

Build the WebRTC SDK in iOS

Complete the following steps:

  1. Import the iOS WebRTC SDK into the XCode integrated development environment (IDE) on an iOS computer by opening KinesisVideoWebRTCDemoApp.xcworkspace (path: amazon-kinesis-video-streams-webrtc-sdk-ios/Swift/AWSKinesisVideoWebRTCDemoApp.xcworkspace).

  2. If you open the project for the first time, it automatically builds. If not, initiate a build.

    You might see the following error:

    error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

    If you see this, do the following:

    • Change your current working directory to amazon-kinesis-video-streams-webrtc-sdk-ios/Swift and run the following in the command line:

      pod cache clean --all pod install
    • Change your current working directory to amazon-kinesis-video-streams-webrtc-sdk-ios and run the following at the command line:

      git checkout Swift/Pods/AWSCore/AWSCore/Service/AWSService.m
    • Build again.

  3. Configure Amazon Cognito (user pool and identity pool) settings. For details steps, see Configure Amazon Cognito for the iOS WebRTC SDK. This generates authentication and authorization settings required to build the iOS WebRTC SDK.

  4. In your IDE, open the awsconfiguration.json file (from /Swift/KVSiOSApp). The file looks like the following:

    { "Version": "1.0", "CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "REPLACEME", "Region": "REPLACEME" } } }, "IdentityManager": { "Default": {} }, "CognitoUserPool": { "Default": { "AppClientSecret": "REPLACEME", "AppClientId": "REPLACEME", "PoolId": "REPLACEME", "Region": "REPLACEME" } } }

    Update awsconfiguration.json with the values generated by running the steps in Configure Amazon Cognito for the Android WebRTC SDK.

  5. In your IDE, open the Constants.swift file (from /Swift/KVSiOSApp). The file looks like the following:

    import Foundation import AWSCognitoIdentityProvider let CognitoIdentityUserPoolRegion = AWSRegionType.USWest2 let CognitoIdentityUserPoolId = "REPLACEME" let CognitoIdentityUserPoolAppClientId = "REPLACEME" let CognitoIdentityUserPoolAppClientSecret = "REPLACEME" let AWSCognitoUserPoolsSignInProviderKey = "UserPool" let CognitoIdentityPoolID = "REPLACEME" let AWSKinesisVideoEndpoint = "https://kinesisvideo.us-west-2.amazonaws.com" let AWSKinesisVideoKey = "kinesisvideo" let VideoProtocols = ["WSS", "HTTPS"] let ConnectAsMaster = "connect-as-master" let ConnectAsViewer = "connect-as-viewer" let MasterRole = "MASTER" let ViewerRole = "VIEWER" let ClientID = "ConsumerViewer"

    Update Constants.swift with the values generated by running the steps in Configure Amazon Cognito for the Android WebRTC SDK.

  6. Make sure your iOS device is connected to the Mac computer where you're running XCode. In XCode, select the connected device and then build and run the WebRTC iOS SDK.

    This step installs an app called AWSKinesisVideoWebRTCDemoApp on your iOS device. Using this app, you can verify live WebRTC audio/video streaming between mobile, web and IoT device clients.

Run the iOS Sample Application

Complete the following steps:

  1. On your iOS device, open AWSKinesisVideoWebRTCDemoApp and log in using either a new (by creating it first) or an existing Amazon Cognito account.

  2. In AWSKinesisVideoWebRTCDemoApp, navigate to the Channel Configuration page and either create a new signaling channel or choose an existing one.

    Note

    Currently, using the sample application in this SDK, you can only run one signalling channel in AWSKinesisVideoWebRTCDemoApp.

  3. (Optional) Choose a unique Client Id if you want to connect to this channel as a viewer. Client Id is required only if multiple viewers are connected to a channel. This helps channel's master identify respective viewers.

  4. Choose the AWS Region and whether you want to send audio or video data, or both.

  5. To verify peer-to-peer streaming, do any of the following:

    Note

    Ensure that you specify the same signaling channel name, AWS region, viewer ID, and the AWS account ID on all clients that you're using in this demo.

    • Peer-to-peer streaming between two iOS devices: master and viewer

      • Using procedures above, download, build, and run the iOS WebRTC SDK on two iOS devices.

      • Open AWSKinesisVideoWebRTCDemoApp on one iOS device in master mode (choose START MASTER) to start a new session (signaling channel).

        Note

        Currently, there can only be one master for any given signaling channel.

      • Open AWSKinesisVideoWebRTCDemoApp on your second iOS device in viewer mode to connect to the signaling channel (session) started in the step above (choose START VIEWER).

        Verify that the viewer can see master's audio/video data.

    • Peer-to-peer streaming between the embedded SDK master and an iOS device viewer

      • Download, build, and run the WebRTC SDK in C for Embedded Devices in master mode on a camera device.

      • Using procedures above, download, build, and run the iOS WebRTC SDK on an iOS device. Open AWSKinesisVideoWebRTCDemoApp on this iOS device in viewer mode and verify that the iOS viewer can see the embedded SDK master's audio/video data.

    • Peer-to-peer streaming between iOS device as master and web browser as viewer

      • Using procedures above, download, build, and run the iOS WebRTC SDK on an iOS device. Open AWSKinesisVideoWebRTCDemoApp on this iOS device in master mode (choose START MASTER) to start a new session (signaling channel).

      • Download, build, and run the WebRTC SDK in JavaScript for Web Applications as viewer and verify that the JavaScript viewer can see the Android master's audio/video.

Configure Amazon Cognito for the iOS WebRTC SDK

Amazon Cognito provides authentication, authorization, and user management for your web and mobile apps. The two main components of Amazon Cognito are user pools and identity pools. User pools are user directories that provide sign-up and sign-in options for your app users. Identity pools enable you to grant your users access to other AWS services.

Use the following procedures to create a user pool and an identity pool to generate the authentication and authorization settings required for building the iOS WebRTC SDK.

To set up Amazon Cognito - User pool

  1. Sign in to the Amazon Cognito console.

  2. Choose Manage your User Pools.

  3. Choose Create a user pool.

  4. Type a value for Pool name; for example, <username>_android_user_pool.

  5. Choose Review defaults.

  6. Choose Create pool.

  7. Copy and save the Pool ID value. You will need this value when you configure the identity pool and the awsconfiguration.json file in the iOS WebRTC SDK.

  8. On the page for your pool, choose App clients.

  9. Choose Add an app client.

  10. Type a value for App client name, for example, <username>_android_app_client.

  11. Choose Create app client.

  12. Choose Show Details, and copy and save the App client ID and App client secret. You will need these values when you configure the identity pool and the awsconfiguration.json file in the iOS WebRTC SDK.

To set up Amazon Cognito - Identity pool

  1. Open the Amazon Cognito console.

  2. Choose Manage Identity Pools.

  3. Choose Create new identity pool.

  4. Type a value for Identity pool name, for example, <username>_android_identity_pool.

  5. Expand the Authentication providers section. On the Cognito tab, add the values for the User Pool ID and App client ID from the previous procedure.

  6. Choose Create pool.

  7. On the next page, expand the Show Details section.

  8. In the section that has a value for Role name that ends in Auth_Role (if you do not have a role, you must create one), choose View Policy Document.

  9. Choose Edit, confirm the Edit Policy dialog box that appears, and then paste the following JSON into the editor:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "cognito-identity:*", "kinesisvideo:*" ], "Resource": [ "*" ] } ] }
  10. Choose Allow.

  11. On the next page, copy and save the Identity pool ID value from the Get AWS Credentials code snippet. You need this value to configure the awsconfiguration.json file in the iOS WebRTC SDK.