Skip to main content

Stream Concurrency

Stream concurrency is a personalization library that facilitates concurrency checks while starting / continuing playback and aborts if the check fails. This is enforced by keeping track of the number of unique active streaming devices for a user. This helps in keeping the concurrent streams in check for any particular user and abort existing / disallow new playback if the number of concurrent streams exceeds allowed limit.
The library relies on the PlatformAuthorizer and the PlatformClient instances to identify the particular user and device.

Manual enforcement

Maintaining the stream concurrency limits can be manually enforced by the application using StreamConcurrencyService.

// endpoint of the stream concurrency microservice. will be provided while on-boarding onto Quickplay platform. 
// the backslash at the end should be included.
val streamConcurrencyEndPointURL = "https://example.com/"
val streamConcurrencyService: StreamConcurrencyService =
StreamConcurrencyFactory.createStreamConcurrencyService(
streamConcurrencyEndPointURL,
platformAuthorizer // the relevant PlatformAuthorizer instance
)


// Put a Stream for a device
val putStreamResult = streamConcurrencyService.putStream(platformClient) // PlatformClient instance
when (putStreamResult) {
is Result.Success -> {
logger.info { "putStream succeeded for device ID ${platformClient.id}"}
}

is Result.Failure -> {
logger.error { "putStream failed with error ${result.value}" }
TODO("Handle putStream call failure as required")
}
}

// Delete the stream for a device
val deleteStreamResult = streamConcurrencyService.deleteStream(platformClient) // PlatformClient instance
when (deleteStreamResult) {
is Result.Success -> {
logger.info { "Stream deleted for device ID ${platformClient.id}"}
}

is Result.Failure -> {
logger.error { "deleteStream failed with error ${result.value}" }
TODO("Handle deleteStream call failure as required")
}
}

Automatic enforcement

Create StreamConcurrencyConfiguration

StreamConcurrencyConfiguration encapsulates all the necessary information required to automate Stream Concurrency.

Property NameTypeDefault ValueDescription
streamConcurrencyEndPointURLStringNAThe endpoint of StreamConcurrency microservice.
platformClientPlatformClientNAThe PlatformClient instance corresponding to the playback.
streamConcurrencySyncIntervalMsLong5000LThe preferred time interval, in milliseconds, to periodically sync the stream's status i.e. trigger a StreamConcurrencyService.putStream call. The stream status is updated every 5 seconds by default.
// endpoint of the stream concurrency microservice. will be provided while on-boarding onto Quickplay platform. 
// the backslash at the end should be included.
val streamConcurrencyEndPointURL = "https://example.com/"

val streamConcurrencySyncIntervalMs = 15_000L // Pass preferred value

val streamConcurrencyConfiguration = StreamConcurrencyManager.StreamConcurrencyConfiguration(
streamConcurrencyEndPointURL,
platformClient, // the relevant PlatformClient instance
streamConcurrencySyncIntervalMs, // Optional, default value is 5000L
)

Create StreamConcurrencyManager

StreamConcurrencyManager takes care of automating all the API calls to maintain and delete the status of a stream. A new StreamConcurrencyManager has to be created before the start of any new playback to maintain accuracy.

StreamConcurrencyFactory.createStreamConcurrencyManager(
player, // the relevant ComposablePlayer instance
platformAuthorizer, // the relevant PlatformAuthorizer instance
streamConcurrencyConfiguration
)
note

A normal Player can be converted into a ComposablePlayer using the composablePlayerWith function.

Once StreamConcurrencyManager is created, it makes sure that the status of the stream is updated periodically and also on applicable player state changes. It also takes care of deleting the stream when the player is stopped.