The source code inside sample-app-src.zip contains an Android application that can be used as a reference for integrating SDK. Further information can be found in the apidocs.zip file.
A customer-specific Operator Vault file (not provided with the SDK or the sample application source) is required to successfully connect with the back end services. There is also a configuration file in the sample application source that requires adjustment.
The SDK is written in Kotlin but is equally easily integrated into Java or Kotlin code.
Instantiation
The OtvSdkClient object can be initialized providing the tenant string via the configuration object and reference to the Application’s context. This is suitable for standard OPF instance base URLs like https://api.<tenant>.opentv.com/.
val client = OtvSdkClient(config = OtvSdkConfig(tenantId = "sales"), context)
Or alternatively initialized providing the full URL if the above URL pattern is not suitable.
val client = OtvSdkClient(config = OtvSdkConfig(URI("https://custom.sales.example.com")), context)
Additional config to override default headers
OtvSdkConfig objects can be augmented using the following functions as required ahead of their use to instantiate OtvSdkClient:
val config = OtvSdkConfig(tenantId = "sales")
.setIasCommonHeaders(mapOf("Content-Type" to "application/custom+json"))
.setIasV3Headers(mapOf("nv-tenant-id" to "tenant-from-app"))
val client = OtvSdkClient(config = config, context)
Determining if previous session has expired
The isExpiredAlready() method returns whether all stored sessions have expired.
val authenticatedOnLaunch = !client.isExpiredAlready()
DAS Sign On
Provide the DRM type from either of
-
com.widevine.alpha -
com.nagra.connect
Provide true if Widevine Level 3 is required
Provide the byte array of the Opvault if using the CONNECT DRM type (com.nagra.connect).
client?.dasLogin(drmType, isL3, opVault)
Or simply auto-login for the CONNECT DRM type, ensure your OpVault file in the src/main/res/raw/ folder and is named connect_opvault.json.
client?.dasLogin()
Get access token
When the App needs to obtain the current token, simply call the getAccessToken() method.
val accessToken = if (authenticatedOnLaunch) client.getAccessToken() else null
Token Refresh Completion
Registering a listener for onRefreshComplete will fire when the access token is refreshed ahead of its expiry.
private fun registerRefreshCallback(
client: OtvSdkClient,
scope: CoroutineScope
) {
client.onTokenRefreshComplete = com.nagra.opentvsdk.TokenRefreshCallback { token, error ->
scope.launch(Dispatchers.Main) {
val item = if (error == null && !token.isNullOrBlank()) {
...
} else {
...
}
...
}
}
}
Sign Out
The signout() function clears the session state and signs out of IAS.
client?.signout()
Get SDK Version
The current SDK’s version can be retrieved using the getSdkVersion():
client.getSdkVersion()