NEWDolby Interactivity APIs are now the Dolby.io Communications APIs Learn More >
X

Initializing

This document explains how to integrate the Dolby.io Communications Client SDKs into your application. If you use UI components, please refer to the UXKit.

Prerequisites

Before using the SDK in your project, find your Consumer Key and Consumer Secret by following these steps:

  1. Select the SIGN IN link located in the upper right corner of the Dolby.io page. Log in using your email and password.
  2. Click the DASHBOARD link visible in the upper right corner of the website.
  3. Select your application from the APPLICATIONS category located on the left side menu.
  4. Select the API Keys category from the drop-down menu visible under your application.
  5. In the Communications APIs section, you can access your Consumer Key and Consumer Secret.

Add the SDK into your application

To add the SDK into your application, you can either use Carthage dependency manager, CocoaPods dependency manager, or the latest VoxeetSDK zip file available on the Voxeet GitHub.

Using Carthage dependency manager:

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

1. Install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

2. To integrate Dolby Interactivity APIs iOS SDK into your Xcode project using Carthage, specify it in your Cartfile:

binary "https://raw.githubusercontent.com/voxeet/voxeet-sdk-ios/master/VoxeetSDK.json" ~> 3.0

3. Run carthage update to build the frameworks and drag VoxeetSDK.framework, WebRTC.framework, and Dvmc.framework into your Xcode project. For more information, see additional Carthage instructions.

Using CocoaPods dependency manager:

Go to the CocoaPods webpage and install the VoxeetSDK.

pod 'VoxeetSDK', '~> 3.0'

Using the latest zip file from the Voxeet GitHub:

1. Download the latest zip file.

2. Unzip the file and drag and drop frameworks into your project.

3. Select the Copy items if needed option and select the proper target.

4. Add the VoxeetSDK.framework, WebRTC.framework, and Dvmc.framework into Embedded Binaries in the general tab of your target.

Initialize the SDK with secure authentication

There are two ways to initialize the SDK. You can either use the recommended secure authentication method or simply embed the app secrets in the app and call the initialize method. For security reasons Dolby recommends the secure authentication method in production; the simpler method is suitable for prototyping of the app.

This section describes how to use the secure method.

The Dolby.io Communications APIs provide an easy to use server-side RESTful API that allows customers’ servers to act as brokers that refresh tokens, so the application secrets are not distributed over the Internet.

The following diagram illustrates the workflow of the secure authentication model.

The secure Auth sequenceThe secure Auth sequence

The secure Auth sequence

Customer’s server

A sample server can be found within the voxeet-io-web repository. The README file explains how to run the server with the secrets for your application.

The examples shown use the API presented by the sample server for communication between the application and the server. The examples assume that this communication is secure and the application is trusted. In a real service, the application’s user would need to log into this server.

Initial authentication

The customer’s server, acting as an authentication broker, needs the application key and secret to authenticate against the /oauth2/token API.
The access token is returned and the customer’s server passes it back to the application.
Upon receiving the access token from the customer’s server, the application calls the initializeToken API to initialize the Dolby.io Communications Client SDKs.

The customer’s server can request the access token with:

let consumerKey = "consumerKey";
let consumerSecret = "consumerSecret";
let authHeader =
  "Basic " + btoa(encodeURI(consumerKey) + ":" + encodeURI(consumerSecret));

let tokenURL = "https://session.voxeet.com/v1/oauth2/token";
let tokenParams = {
  method: "POST",
  headers: {
    Authorization: authHeader,
  },
  body: {
    grant_type: "client_credentials",
  },
};

var access_token;

fetch(tokenURL, tokenParams)
  .then((data) => data.json())
  .then((result) => {
    access_token = result.access_token;
    // Return the access_token to the application

    console.log(`returned access_token is ${result.access_token}`);
  });

When the application has received the access token from the customer’s server, it can initialize the SDK with:

import VoxeetSDK

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    func fetchToken(completion: @escaping (_ token: String?) -> Void) {
        let url = URL(string: serverURL + "/api/token")!
        let task = URLSession.shared.dataTask(with: url) { data, _, _ in
            if let data = data,
              let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
              let accessToken = json["access_token"] as? String {
                completion(accessToken)
            } else {
                completion(nil)
            }
        }
        task.resume()
    }

    func application(
        application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {

        // Fetch access token.
        fetchToken { accessToken in
            guard let token = accessToken else { return }

            // Voxeet SDK OAuth initialization.
            VoxeetSDK.shared.initialize(accessToken: token) { refreshClosure in
                // VoxeetSDK calls this closure when the token needs to be refreshed.
                // See the next section for details.
            }
        }

        return true
    }
}

Refresh authentication

An access token has a limited period of validity and needs periodic refreshing. In the application, the Dolby.io Communications Client SDKs invokes the callback provided to the initialize call when the access token needs to be refreshed. This callback contacts the customer’s server, which in turn calls the /oauth2/token API again and returns the refreshed token, which is passed back to the Client SDK by the application.

When the application has received the refreshed access token from the customer’s server, it can pass this to the SDK with this change:

// The last parameter passed to `VoxeetSDK.initialize(accessToken:refreshTokenClosure:)` 
// is a closure that is called when the token needs to be refreshed. This 
// closure is passed a single parameter, which is a `VoxeetSDK` closure, which 
// the application calls with the refreshed access token

import VoxeetSDK

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    ...

    func application(
        application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {

        // Fetch access token.
        fetchToken { accessToken in
            guard let token = accessToken else { return }

            // Voxeet SDK OAuth initialization.
            VoxeetSDK.shared.initialize(accessToken: token) { refreshClosure in
                // VoxeetSDK calls this closure when the token needs to be refreshed.
                fetchToken { accessToken in
                    guard let token = accessToken else { return }

                    // Call the SDK’s refresh closure with the new token
                    refreshClosure(token)
                }
            }
        }

        return true
    }
}

Open a session

let info = VTParticipantInfo(externalID: nil, name: "Username", avatarURL: nil)
VoxeetSDK.shared.session.open(info: info) { error in

Close a session

VoxeetSDK.shared.session.close { error in

Result

The Dolby.io Communications Client SDKs is integrated with your application, so you have access to all SDK functionalities.

Now you can easily configure your SDK. Tutorials available in the left-side navigation panel and reference documentation guides how to do it.


Did this page help you?