Skip to main content

Heartbeat

The heartbeat library is a personalization library that facilitates stream concurrency. Playback would be aborted when the concurrent streams reaches allowed limit.

Create HeartbeatManager​

Wiring Authorization Response​

Once an asset is authorized for Playback (refer Authorize Playback for an Asset), the authorization includes the following heartbeat info, which should be used while setting up the heartbeat.

NameDescription
heartbeatFlagIndicates whether heartbeat should be attached for the current playback (e.g., heartbeat is not required for blacked-out streams or certain VOD catalog types)
heartbeatFreqThe recommended heartbeat sync interval in milli-seconds
heartbeatTokenThe unique hearbeat token for the current playback
liveStartTimeStart time of the current live program/live event.
liveEndTimeEnd Time of the current live program/live event.
catalogTypeThe value of the Catalog type of content.
primaryContentIdThe unique identifier of the primary content to which the selected content (i.e. secondary angle content) to play is associated with. This is applicable only for multi-camera enabled content.
live360StartTimeThe start time of the live 360 camera supported content.
live360EndTimeThe end time of the live 360 camera supported content.
freePreviewFree preview allowance metadata (for example, fpMode, totalDuration, remainingDuration). Refer to Free Preview.

Configuration​

NameRequiredDescription
heartbeatEndPointUrltrueHeartbeat service end-point url.
streamConcurrencyEndPointUrlfalseStream Concurrency service end-point url.
syncIntervalMSfalseThe time interval in milliseconds used to periodically update stream state of the currently playing content. Default: 60000ms.
maxAllowedFailuresfalseThe maximum number of failed heartbeat check attempts (network or infrastructure issues) that are allowed to happen in line before the Live content's playback is terminated. Default: 2.
recordBookmarkfalseSpecifies whether to use the heartbeat service to record bookmarks/resume points for VOD contents. Default: false.
stopPlayerOnStreamTimelineEventfalseSpecifies whether to stop the player for Live contents on stream timeline events. Default: true. Free-preview expiry and GRACEFUL_STOP stop playback regardless of this setting.
showPostEventSlateTimeMsfalseThe post-event configuration time in milliseconds used to stop the overflow event after a live event ends. Default: 900000ms (15 minutes).
multiStreamModefalseIndicates if the current device is streaming multiple videos using multiple player instances (for example, in MultiView mode or when swapping between Live and Restart streams).
maxRetriesfalseThe maximum retries for network request failure or timeout.
trackViewersCountfalseThe flag indicates whether to track the viewers count or not, for the content to play. Default: false.
freePreviewExtensionCheckSecfalseThe lead time in seconds before preview expiration to check for extensions. Default: 60s. Refer to Free Preview.
jitterSecfalseMaximum initial light-preview random offset in seconds, rounded down to 10-second buckets. Default: 60s; 0 disables jitter. Refer to Free Preview.
onFreePreviewExtensionfalseCallback invoked in light preview mode to request additional preview seconds or decline ((preview: Readonly<FreePreview>) => Promise<number>). Refer to Free Preview.
onFreePreviewProgressfalseCallback reporting the initial allowance and changes in displayed whole seconds remaining ((preview: Readonly<FreePreview>) => void). Refer to Free Preview.
const heartbeatConfiguration = {
heartbeatEndPointUrl: heartbeatEndPointUrl,
streamConcurrencyEndPointUrl: streamConcurrencyEndPointUrl,
syncIntervalMS: heartbeatFreq,
};

return flHeartbeat
.createHeartbeatBuilder(
deviceId,
contentId,
heartbeatConfiguration,
platformAuthorizer,
)
.setHeartbeatToken(heartbeatToken)
.setLiveEndTime(liveEndTime)
.setLiveStartTime(liveStartTime)
.build();

Reserve Stream on Player Load​

Call setReserveStreamOnPlayerLoad(true) on the builder when playback authorization didn't reserve a stream slot, for example for content you authorized with preload: true (refer to Prefetch Content). The HeartbeatManager then reserves the stream itself through /user/stream/create.

  • When it reserves: when the player reaches LOADED. If the player never emits LOADED, it reserves on the first STARTED instead. It reserves only once per load.
  • Requirements: set streamConcurrencyEndPointUrl in the configuration. Without it, the HeartbeatManager doesn't reserve a stream and doesn't report an error. The request uses the heartbeatToken you pass to setHeartbeatToken().
  • On failure: the player aborts playback and emits an error event with the error returned by the stream concurrency service, for example when the concurrent-stream limit is reached. Because the reservation runs at LOADED, a rejected session stops before playback starts.

When the flag is false or not set, the HeartbeatManager doesn't reserve a stream on load, which is the default behavior.

const heartbeatManager = flHeartbeat
.createHeartbeatBuilder(
deviceId,
contentId,
{
heartbeatEndPointUrl: heartbeatEndPointUrl,
streamConcurrencyEndPointUrl: streamConcurrencyEndPointUrl,
syncIntervalMS: contentAuthorizationData.heartbeatFreq,
},
platformAuthorizer,
)
.setHeartbeatToken(contentAuthorizationData.heartbeatToken)
.setReserveStreamOnPlayerLoad(true)
.build();

player.subscribe('error', error => {
// For example, show a "too many devices streaming" message.
});
note

setReserveStreamOnPlayerLoad() requires Web SDK 7.1.297 or later.

Attach Heartbeat to Player​

HeartbeatManager could be attached to a Player by attaching the exposed processPlayerStateChange, processHeartbeatChange callback to ComposablePlayer's addStateChangeStep, processHeartbeatChange life-cycle method.

const composablePlayer = flPlatformPlayer.createComposablePlayer(player);
composablePlayer.addStateChangeStep(heartbeatManager.processPlayerStateChange);

composablePlayer.addHeartBeatStep(heartbeatManager.processHeartbeatChange);

Stream Reservation on Resume​

When you configure streamConcurrencyEndPointUrl, the HeartbeatManager releases the stream slot when the player pauses, stops, or goes idle, and reserves it again through /user/stream/create when playback resumes. In multiStreamMode, it keeps the slot instead of releasing it.

If the reservation on resume fails, the player aborts playback and emits an error event with the error returned by the stream concurrency service. For example, this happens when another device starts streaming while this one is paused and the account reaches its concurrent-stream limit. Handle the error event to show your app's concurrency message.

note

From Web SDK 7.1.297, a failed reservation on resume aborts playback. Earlier versions ignored the failure and continued playback.

Blackouts​

While authorizing an asset for Playback, the server might enforce Blackout rules based on tenent specific configuration. When a playback is attempted from a Blacked-out region, the server would respond with the following:

NameDescription
blackoutActionIndicates appropriate action for Blackout scenario. Possible Values: ALLOW, DENY, ALLOW_WITH_UPGRADE.
blackoutUrlThe alternate blackout slate stream to play while the user is in blackout.
note

When receiving a blackoutAction other than ALLOW, the application must play the blackoutUrl instead if the regular contentUrl.

Roaming​

Blackouts are also detected and enforced via heartbeat to ensure when the user is roaming to a blacked-out region, they are no longer able to stream the content. When detecting a blackout, the HeartbeatManager would abort the player and player emits a streamtimelineevent event with blackout action. Application could subscribe to this event manage the blackout based on the UX requirements (typically, swap the on-going player with a player playing blacked-out slate).

  player.subscribe("streamtimelineevent", async function (streamTimelineEvent, action, metadata) {

switch (streamTimelineEvent) {
case flPlayerInterface.StreamTimelineEvent.BLACKOUT: {
console.log("Blackout Url", blackoutMetadata.blackoutUrl);
// Create a new player instance and play the blackout Url.
break;
}
}

});

Events during Live Streams​

All the applicable events for different type of live streams are part of StreamTimelineEvent and can be notified to the client application using Heartbeat.

NameDescription
LIVE_EVENT_STARTThe start of a one-time Live event.
LIVE_EVENT_ENDThe end of a one-time live event.
OVERFLOW_EVENT_ENDThe end of an overflow event. Applicable only for Overflow events.
BLACKOUTThe playback has blacked out.
LIVE_360_AVAILABLEThe availability of 360 degree mode
LIVE_360_UNAVAILABLEThe unavailability of 360 degree mode