WebRTC SDK for Android - Kinesis Video Streams

WebRTC SDK for Android

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

Download the WebRTC SDK for Android

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

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

Build the WebRTC SDK in Android

To build the WebRTC SDK in Android, complete the following steps:

  1. Import the Android WebRTC SDK into the Android Studio integrated development environment (IDE) by opening amazon-kinesis-video-streams-webrtc-sdk-android/build.gradle with Open as Project.

  2. If you open the project for the first time, it automatically syncs. If not - initiate a sync. When you see a build error, choose to install any required SDKs by choosing Install missing SDK package(s), then choose Accept and complete the install.

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

  4. In your Android IDE, open awsconfiguration.json (from src/main/res/raw/). The file looks like the following:

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

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

  5. Make sure your Android device is connected to the computer where you're running the Android IDE. In the Android IDE, select the connected device and then build and run the WebRTC Android SDK.

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

Run the Android Sample Application

Complete the following steps:

  1. On your Android 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 Android devices: master and viewer

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

      • Open AWSKinesisVideoWebRTCDemoApp on one Android 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 Android 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 Android 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 Android WebRTC SDK on an Android device. Open AWSKinesisVideoWebRTCDemoApp on this Android device in viewer mode and verify that the viewer can see the embedded SDK master's audio/video data.

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

      • Using procedures above, download, build, and run the Android WebRTC SDK on an Android device. Open AWSKinesisVideoWebRTCDemoApp on this Android 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 viewer can see the Android master's audio/video.

Configure Amazon Cognito for the Android 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 Android 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 Android 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 Android 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 Android WebRTC SDK.